Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[DependencyInjection] Add exclude to TaggedIterator and TaggedLocator#17645
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -591,6 +591,76 @@ application handlers:: | ||
| } | ||
| } | ||
| If for some reason you need to exclude one or multiple services when using a tagged | ||
| iterator, this can be done by using the ``exclude`` option: | ||
| .. configuration-block:: | ||
| .. code-block:: yaml | ||
| # config/services.yaml | ||
| services: | ||
| # ... | ||
| # This is the service we want to exclude, even if the 'app.handler' tag is attached | ||
| App\Handler\Three: | ||
| tags: ['app.handler'] | ||
| App\HandlerCollection: | ||
| arguments: | ||
| - !tagged_iterator { tag: app.handler, exclude: ['App\Handler\Three'] } | ||
| .. code-block:: xml | ||
| <!-- config/services.xml --> | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <container xmlns="http://symfony.com/schema/dic/services" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
| https://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
| <services> | ||
| <!-- ... --> | ||
| <!-- This is the service we want to exclude, even if the 'app.handler' tag is attached --> | ||
| <service id="App\Handler\Three"> | ||
| <tag name="app.handler"/> | ||
| </service> | ||
| <service id="App\HandlerCollection"> | ||
| <!-- inject all services tagged with app.handler as first argument --> | ||
| <argument type="tagged_iterator" tag="app.handler"> | ||
| <exclude>App\Handler\Three</exclude> | ||
| </argument> | ||
| </service> | ||
| </services> | ||
| </container> | ||
| .. code-block:: php | ||
| // config/services.php | ||
| namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
| return function(ContainerConfigurator $configurator) { | ||
| $services = $configurator->services(); | ||
| // ... | ||
| // This is the service we want to exclude, even if the 'app.handler' tag is attached | ||
| $services->set(App\Handler\Three::class) | ||
| ->tag('app.handler') | ||
| ; | ||
| $services->set(App\HandlerCollection::class) | ||
| // inject all services tagged with app.handler as first argument | ||
| ->args([tagged_iterator('app.handler', exclude: [App\Handler\Three::class])]) | ||
| ; | ||
| }; | ||
| .. versionadded:: 6.1 | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
Nevermind, I just saw that the initial implementation was done in 6.1. | ||
| The ``exclude`` option was introduced in Symfony 6.1. | ||
| .. seealso:: | ||
| See also :doc:`tagged locator services </service_container/service_subscribers_locators>` | ||