-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Allow array for the value of Autowire attribute #47801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you @willemverspyck. |
string $service = null, | ||
string $expression = null, | ||
) { | ||
if (!($service xor $expression xor null !== $value)) { | ||
throw new LogicException('#[Autowire] attribute must declare exactly one of $service, $expression, or $value.'); | ||
} | ||
|
||
if (null !== $value && str_starts_with($value, '@')) { | ||
if (\is_string($value) && str_starts_with($value, '@')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For an array, wouldn't this need to process the strings inside that array to convert their prefixes too ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to allow nesting services into arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do allow that in Yaml or XML (which is how you passed an array of objects indexed by some keys for instance)
Thanks for reviewing @fabpot and @nicolas-grekas 👍 |
Since Symfony 6.1 it's possible to use #[Autowire] for the service autowiring logic. Array as autowire parameters is not supported yet. In YAML or the attribute Autoconfigure it worked.
After this PR there is support for an array (including some extra tests):