magento2
magento2 copied to clipboard
[Issue] Typed variadic arguments fail to be injected
This issue is automatically created based on existing pull request: magento/magento2#30888: Typed variadic arguments fail to be injected
Description (*)
Related with https://github.com/magento/magento2/pull/24556.
That PR allowed to inject scalar values as variadic parameters, but does not work for object injections. Object definitions don't get instantiated, and target class constructor receives an array of strings instead (with '_instance' key, that should have been transformed into real objects).
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- Declare di arguments injection -->
<type name="Interactiv4\EmailAttachments\Mail\AttachmentsProcessor">
<arguments>
<!-- This argument is a typed variadic one -->
<argument name="attachmentProviders" xsi:type="array">
<!-- This argument value is an object implementing variadic argument type -->
<item name="invoice" xsi:type="object">Interactiv4\SalesEmailAttachments\Mail\AttachmentProvider\InvoiceAttachmentProvider</item>
</argument>
</arguments>
</type>
</config>
With proposed change, variadic arguments are interpreted when needed to be transformed into real objects. Scalar/other variadic arguments will continue working as previously.
Related Pull Requests
https://github.com/magento/magento2/pull/24556
Fixed Issues (if relevant)
None AFAIK.
Manual testing scenarios (*)
- Create a class with a typed variadic argument in it:
class Test
{
public function __construct(SomeInterface ...$interfaceInstances){}
}
- Inject via di.xml instances of given interface, similar as shown in summary.
- Prior to this proposed change it fails complaining of type error on object construct.
Questions or comments
Contribution checklist (*)
- [x] Pull request has a meaningful description of its purpose
- [x] All commits are accompanied by meaningful commit messages
- [ ] All new or changed code is covered with unit/integration tests (if applicable)
- [ ] All automated tests passed successfully (all builds are green)
Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
- [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
- [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
- [ ] 3. Add
Area: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced on 2.4.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! - [ ] 5. Add label
Issue: Confirmedonce verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @adrian-martinez-interactiv4,
Thank you for the report and collaboration!
Not able to reproduce this on 2.4-develop. We are able to inject typed variadic arguments.
Please find the module used to reproduce this. I30931V.zip
Thank you.
Hi @adrian-martinez-interactiv4,
This issue is being closed since it has not been updated in a long time.Please feel free to reopen or raise a new ticket if the issue still exists.
Thanks.