diff --git a/service_container/tags.rst b/service_container/tags.rst index 9c89ef8c85a..e5e996a076e 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -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 + + + + + + + + + + + + + + + + + App\Handler\Three + + + + + + .. 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 + + The ``exclude`` option was introduced in Symfony 6.1. + .. seealso:: See also :doc:`tagged locator services ` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy