-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Autowire error with Symfony Flex when configuring argument by name #23308
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
Comments
If you want use a named arguments, just change definiton:
|
Any name/value that starts with special character needs to be quoted: |
In this case quoted: |
But: 1> It's not what the documentation says
I don't think the problem come from the definition. It's just that with Flex install, when configuring an argument by name, other arguments are no longer autowired |
@ByScripts : autowiring is not enabled in Enable autowiring for all services declared inside the file (+ private by default & autoconfigure) by adding this to the services:
_defaults: { public: false, autowire: true, autoconfigure: true }
# ... |
or enable autowiring just for this service |
Thank you. Yet, autowiring works if I don't add the string param... why ? Edit: Nevermind, I understand what @ogizanagi means. Thank you. |
It's not autowiring, it the named arguments feature: #21383 |
So... now I understand. But I think it's a "strange" behavior. The app is configured to autowire by default ( But I think it'll be pretty common to need to configure a named parameter. And since for that we declare the service in Other solution would be to use the Last is what @ogizanagi proposes. Addind the But should not the Because it feels inconsistent to me, no? |
I clone your repo and try my solution with:
And it works without any configuration. If you use named arguments just define it with array. |
@shude It fixes the error when running I created a Command, then injected
Like @ogizanagi said, autowiring is not configured in this file ( |
Sorry, I was wrong. If manualy set autowire to true it works fine. i think, It should be written in the documentation |
@ByScripts can you close here (and maybe open a doc PR or issue also?) |
I've just opened symfony/symfony-docs#8242, we can close here. |
There seems to be a problem with autowiring when using Symfony Flex, but not when using a standard
symfony new
project.When configuring an argument by name (
arguments: { $argName: 'value' }
), other arguments are no longer autowired.At the beginning, I had this service, which was working fine (autowiring works as expected):
But then I needed to add a second argument, a plain string. So I did it like this:
Then I updated
container.yaml
accordingly:But now I have this error:
If I move the string argument to first position, then I have this error:
Here is two demo project, configured the same way. One with Symfony Flex, other as a standard
symfony new
project:Flex: https://github.com/ByScripts/sf-issue-autowire-flex
Standard: https://github.com/ByScripts/sf-issue-autowire
Just
git clone
,composer install
, then runbin/console
on both project.The text was updated successfully, but these errors were encountered: