Skip to content

Commit fde9603

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: [DependencyInjection] Add exclude to TaggedIterator and TaggedLocator
2 parents 31f69fa + cf1b86e commit fde9603

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

service_container/tags.rst

+70
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,76 @@ application handlers::
591591
}
592592
}
593593

594+
If for some reason you need to exclude one or more services when using a tagged
595+
iterator, add the ``exclude`` option:
596+
597+
.. configuration-block::
598+
599+
.. code-block:: yaml
600+
601+
# config/services.yaml
602+
services:
603+
# ...
604+
605+
# This is the service we want to exclude, even if the 'app.handler' tag is attached
606+
App\Handler\Three:
607+
tags: ['app.handler']
608+
609+
App\HandlerCollection:
610+
arguments:
611+
- !tagged_iterator { tag: app.handler, exclude: ['App\Handler\Three'] }
612+
613+
.. code-block:: xml
614+
615+
<!-- config/services.xml -->
616+
<?xml version="1.0" encoding="UTF-8" ?>
617+
<container xmlns="http://symfony.com/schema/dic/services"
618+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
619+
xsi:schemaLocation="http://symfony.com/schema/dic/services
620+
https://symfony.com/schema/dic/services/services-1.0.xsd">
621+
622+
<services>
623+
<!-- ... -->
624+
625+
<!-- This is the service we want to exclude, even if the 'app.handler' tag is attached -->
626+
<service id="App\Handler\Three">
627+
<tag name="app.handler"/>
628+
</service>
629+
630+
<service id="App\HandlerCollection">
631+
<!-- inject all services tagged with app.handler as first argument -->
632+
<argument type="tagged_iterator" tag="app.handler">
633+
<exclude>App\Handler\Three</exclude>
634+
</argument>
635+
</service>
636+
</services>
637+
</container>
638+
639+
.. code-block:: php
640+
641+
// config/services.php
642+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
643+
644+
return function(ContainerConfigurator $configurator) {
645+
$services = $configurator->services();
646+
647+
// ...
648+
649+
// This is the service we want to exclude, even if the 'app.handler' tag is attached
650+
$services->set(App\Handler\Three::class)
651+
->tag('app.handler')
652+
;
653+
654+
$services->set(App\HandlerCollection::class)
655+
// inject all services tagged with app.handler as first argument
656+
->args([tagged_iterator('app.handler', exclude: [App\Handler\Three::class])])
657+
;
658+
};
659+
660+
.. versionadded:: 6.1
661+
662+
The ``exclude`` option was introduced in Symfony 6.1.
663+
594664
.. seealso::
595665

596666
See also :doc:`tagged locator services </service_container/service_subscribers_locators>`

0 commit comments

Comments
 (0)