magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

[Issue] Typed variadic arguments fail to be injected

Open m2-assistant[bot] opened this issue 5 years ago • 2 comments

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 (*)

  1. Create a class with a typed variadic argument in it:
class Test
{
    public function __construct(SomeInterface ...$interfaceInstances){}
}
  1. Inject via di.xml instances of given interface, similar as shown in summary.
  2. 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)

m2-assistant[bot] avatar Nov 16 '20 16:11 m2-assistant[bot]

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: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Jun 26 '24 09:06 m2-assistant[bot]

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.

engcom-November avatar Jun 26 '24 09:06 engcom-November

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.

engcom-Bravo avatar Dec 09 '24 04:12 engcom-Bravo