Commit 723ab0a
committed
minor #12452 Fixed: tagged services YAML example can be misleading (romaricdrigon)
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 example1 file changed
+2
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
466 | 466 | | |
467 | 467 | | |
468 | 468 | | |
469 | | - | |
| 469 | + | |
| 470 | + | |
470 | 471 | | |
471 | 472 | | |
472 | 473 | | |
| |||
0 commit comments