@@ -838,10 +838,88 @@ iterator, add the ``exclude`` option:
838
838
;
839
839
};
840
840
841
- .. note ::
841
+ In the case the referencing service is itself tagged with the tag being used in the tagged
842
+ iterator, it is automatically excluded from the injected iterable. This behavior can be
843
+ disabled by setting the ``exclude_self `` option to ``false ``:
844
+
845
+ .. configuration-block ::
846
+
847
+ .. code-block :: php-attributes
848
+
849
+ // src/HandlerCollection.php
850
+ namespace App;
851
+
852
+ use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
853
+
854
+ class HandlerCollection
855
+ {
856
+ public function __construct(
857
+ #[TaggedIterator('app.handler', exclude: ['App\Handler\Three'], excludeSelf: false)]
858
+ iterable $handlers
859
+ ) {
860
+ }
861
+ }
862
+
863
+ .. code-block :: yaml
864
+
865
+ # config/services.yaml
866
+ services :
867
+ # ...
842
868
843
- In the case the referencing service is itself tagged with the tag being used in the tagged
844
- iterator, it is automatically excluded from the injected iterable.
869
+ # This is the service we want to exclude, even if the 'app.handler' tag is attached
870
+ App\Handler\Three :
871
+ tags : ['app.handler']
872
+
873
+ App\HandlerCollection :
874
+ arguments :
875
+ - !tagged_iterator { tag: app.handler, exclude: ['App\Handler\Three'], exclude_self: false }
876
+
877
+ .. code-block :: xml
878
+
879
+ <!-- config/services.xml -->
880
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
881
+ <container xmlns =" http://symfony.com/schema/dic/services"
882
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
883
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
884
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
885
+
886
+ <services >
887
+ <!-- ... -->
888
+
889
+ <!-- This is the service we want to exclude, even if the 'app.handler' tag is attached -->
890
+ <service id =" App\Handler\Three" >
891
+ <tag name =" app.handler" />
892
+ </service >
893
+
894
+ <service id =" App\HandlerCollection" >
895
+ <!-- inject all services tagged with app.handler as first argument -->
896
+ <argument type =" tagged_iterator" tag =" app.handler" exclude-self =" false" >
897
+ <exclude >App\Handler\Three</exclude >
898
+ </argument >
899
+ </service >
900
+ </services >
901
+ </container >
902
+
903
+ .. code-block :: php
904
+
905
+ // config/services.php
906
+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
907
+
908
+ return function(ContainerConfigurator $containerConfigurator) {
909
+ $services = $containerConfigurator->services();
910
+
911
+ // ...
912
+
913
+ // This is the service we want to exclude, even if the 'app.handler' tag is attached
914
+ $services->set(App\Handler\Three::class)
915
+ ->tag('app.handler')
916
+ ;
917
+
918
+ $services->set(App\HandlerCollection::class)
919
+ // inject all services tagged with app.handler as first argument
920
+ ->args([tagged_iterator('app.handler', exclude: [App\Handler\Three::class], excludeSelf: false)])
921
+ ;
922
+ };
845
923
846
924
.. seealso ::
847
925
0 commit comments