8000 How to configure named argument with variadics and autowire in YAML? · Issue #24935 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
How to configure named argument with variadics and autowire in YAML? #24935
Closed
@PabloKowalczyk

Description

@PabloKowalczyk
Q A
Bug report? yes/no
Feature request? yes/no
BC Break report? no
RFC? no
Symfony version 3.3

Hello,

I'm wondering how to configure named argument with variadics parameter and autowire.

Please look at these example classes:

class Bar
{
}
class Foo
{
    public function __construct(PropertyAccessorInterface $propertyAccessor, Bar ...$bars)
    {
        // ...
    }
}

As we can see, class Foo has $bars constructor param as a variadic.
Without autowire i can configure it as presented below:

bar1:
  class: Bar

bar2:
  class: Bar

Foo:
  arguments:
    - '@property_accessor'
    - '@bar1'
    - '@bar2'

Now, i would like to use autowire feature, but i don't know how to configure it.

Below config doesn't work - exception Type error: Argument 2 passed to Foo::__construct() must be an instance of Bar, array given:

Foo:
  autowire: true
  arguments:
    $bars:
      - '@bar1'
      - '@bar2'

Below config works but only last service is injected:

Foo:
  autowire: true
  arguments:
    $bars: '@bar1'
    $bars: '@bar2'

Is there any way to configure it properly?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0