-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fixed: tagged services YAML example can be misleading #12452
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
the
services:
App\HandlerCollection:
arguments: [@router] is exactly the same than
And after parsing the Yaml, we cannot even know which syntax was seen by the parser (which is totally expected). note that the same is true for mappings (think about JS object literals). They also have an inline syntax (using so this is absolutely not a non-standard notation. |
I prefer short notation in case there is one argument only, like it is now. When using yaml, you need to know the yaml syntax and this error was good for your colleague to learn it |
@stof I get that, and I understand @ostrolucky I can't help but feel it is a little bit unsensitive to say "people will learn the hard way". |
I have no facts pointing out that either the inline or the nested notation are easier to understand. But I can see that copying a single argument is easier when using the nested notation. That would actually be an argument for me in of using it in favour of the inline notation. |
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 agree with @xabbuh and @romaricdrigon here that the nested notation is easier to copy (and thus, at least, easier to use in your application when reading the docs). (also funny to see the GitHub parser understanding the tag in the nested example, but failing to do so in the inline variant).
We're getting in the weird zone of Yaml here though: - !tagged something
looks really scary and would blow my mind when I would first see it in the docs. I guess there is not so much we can do here besides using the nested variant (maybe explain that !tagged
is a Yaml tag. Anyway, 👍
Thank you Romaric. |
…omaricdrigon) This PR was merged into the 3.4 branch. Discussion ---------- Fixed: tagged services YAML example can be misleading Hello, At the moment, I find [tagged services example](https://symfony.com/doc/current/service_container/tags.html#reference-tagged-services) in YAML to be misleading: ```yaml # config/services.yaml services: App\HandlerCollection: # inject all services tagged with app.handler as first argument arguments: [!tagged app.handler] ``` `[!tagged app.handler]` means all tagged services, which is a `RewindableGenerator`, to be injected **as the array of** arguments. It combines both a syntax specific _to injecting the array of arguments_, and the `!tagged app.handler` syntax, to get _an array of tagged services_ (moreover, which is a non-standard and uncommon syntax). Having both syntax, both arrays, shown at the same time makes the snippet hard to grasp for newcomers. We had the issue with a coworker a few minutes ago, he did this naively: ```yaml services: App\HandlerCollection: arguments: - @router - @my_other_service - [!tagged app.handler] ``` And we lost some time to debug why we where getting an array of `RewindableGenerator`. This PR simplifies YAML example to use a more common, more readable, and less risky to modify syntax: ```yaml services: App\HandlerCollection: arguments: - !tagged app.handler ``` I think it will be clearer to newcomers. I believe it also makes YAML example closer to XML example, since XML does not have a syntax for "array of all arguments passed to that service". Commits ------- 0f4a7a1 Simplified tagged services YAML example
Hello,
At the moment, I find tagged services example in YAML to be misleading:
[!tagged app.handler]
means all tagged services, which is aRewindableGenerator
, to be injected as the array of arguments. It combines both a syntax specific to injecting the array of arguments, and the!tagged app.handler
syntax, to get an array of tagged services (moreover, which is a non-standard and uncommon syntax).Having both syntax, both arrays, shown at the same time makes the snippet hard to grasp for newcomers.
We had the issue with a coworker a few minutes ago, he did this naively:
And we lost some time to debug why we where getting an array of
RewindableGenerator
.This PR simplifies YAML example to use a more common, more readable, and less risky to modify syntax:
I think it will be clearer to newcomers.
I believe it also makes YAML example closer to XML example, since XML does not have a syntax for "array of all arguments passed to that service".