Closed
Description
This issue is automatically created based on existing pull request: #30888: Typed variadic arguments fail to be injected
Description (*)
Related with #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
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 (*)
- Pull request has a meaningful description of its purpose
- 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)