This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony
Nyholm 59211ce286
feature #40800 [DependencyInjection] Add #[Target] to tell how a dependency is used and hint named autowiring aliases (nicolas-grekas)
This PR was merged into the 5.3-dev branch.

Discussion
----------

[DependencyInjection] Add `#[Target]` to tell how a dependency is used and hint named autowiring aliases

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Right now, when one wants to target a specific service in a list of candidates, we rely on the name of the argument in addition to the type-hint, eg:

`function foo(WorkflowInterface $reviewStateMachine)`

The deal is that by giving the argument a name that matches the target use case of the required dependency, we make autowiring more useful.

But sometimes, being able to de-correlate the name of the argument and the purpose is desired.

This PR introduces a new `#[Target]` attribute on PHP8 that allows doing so. The previous example could be written as such thanks to it:

`function foo(#[Target('review.state_machine')] WorkflowInterface $workflow)`

That's all folks :)

Commits
-------

cc76eab795 [DependencyInjection] Add `#[Target]` to tell how a dependency is used and hint named autowiring aliases
2021-04-19 15:08:09 +02:00
..
Bridge Merge branch '5.2' into 5.x 2021-04-16 19:25:45 +02:00
Bundle feature #40800 [DependencyInjection] Add #[Target] to tell how a dependency is used and hint named autowiring aliases (nicolas-grekas) 2021-04-19 15:08:09 +02:00
Component feature #40800 [DependencyInjection] Add #[Target] to tell how a dependency is used and hint named autowiring aliases (nicolas-grekas) 2021-04-19 15:08:09 +02:00
Contracts Merge branch '5.2' into 5.x 2021-04-12 01:07:08 +02:00