Skip to content

[Issue] Typed variadic arguments fail to be injected #30931

Closed
@m2-assistant

Description

@m2-assistant

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

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

  • 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)

Metadata

Metadata

Labels

Component: ObjectManagerIssue: needs updateAdditional information is require, waiting for responsePriority: P3May be fixed according to the position in the backlog.Progress: doneSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions