File tree Expand file tree Collapse file tree 2 files changed +82
-0
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +82
-0
lines changed
Original file line number Diff line number Diff line change @@ -516,6 +516,23 @@ of the ``key`` tag attribute (as defined in the ``index_by`` locator option):
516
516
517
517
.. configuration-block ::
518
518
519
+ .. code-block :: php-attributes
520
+
521
+ // src/CommandBus.php
522
+ namespace App;
523
+
524
+ use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
525
+ use Symfony\Component\DependencyInjection\ServiceLocator;
526
+
527
+ class CommandBus
528
+ {
529
+ public function __construct(
530
+ #[TaggedLocator('app.handler', indexAttribute: 'key')]
531
+ ServiceLocator $locator
532
+ ) {
533
+ }
534
+ }
535
+
519
536
.. code-block :: yaml
520
537
521
538
# config/services.yaml
@@ -619,6 +636,23 @@ attribute to the locator service defining the name of this custom method:
619
636
620
637
.. configuration-block ::
621
638
639
+ .. code-block :: php-attributes
640
+
641
+ // src/CommandBus.php
642
+ namespace App;
643
+
644
+ use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
645
+ use Symfony\Component\DependencyInjection\ServiceLocator;
646
+
647
+ class CommandBus
648
+ {
649
+ public function __construct(
650
+ #[TaggedLocator('app.handler', 'key', defaultIndexMethod: 'myOwnMethodName')]
651
+ ServiceLocator $locator
652
+ ) {
653
+ }
654
+ }
655
+
622
656
.. code-block :: yaml
623
657
624
658
# config/services.yaml
Original file line number Diff line number Diff line change @@ -707,6 +707,22 @@ you can define it in the configuration of the collecting service:
707
707
708
708
.. configuration-block ::
709
709
710
+ .. code-block :: php-attributes
711
+
712
+ // src/HandlerCollection.php
713
+ namespace App;
714
+
715
+ use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
716
+
717
+ class HandlerCollection
718
+ {
719
+ public function __construct(
720
+ #[TaggedIterator('app.handler', defaultPriorityMethod: 'getPriority')]
721
+ iterable $handlers
722
+ ) {
723
+ }
724
+ }
725
+
710
726
.. code-block :: yaml
711
727
712
728
# config/services.yaml
@@ -762,6 +778,22 @@ indexed by the ``key`` attribute:
762
778
763
779
.. configuration-block ::
764
780
781
+ .. code-block :: php-attributes
782
+
783
+ // src/HandlerCollection.php
784
+ namespace App;
785
+
786
+ use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
787
+
788
+ class HandlerCollection
789
+ {
790
+ public function __construct(
791
+ #[TaggedIterator('app.handler', indexAttribute: 'key')]
792
+ iterable $handlers
793
+ ) {
794
+ }
795
+ }
796
+
765
797
.. code-block :: yaml
766
798
767
799
# config/services.yaml
@@ -868,6 +900,22 @@ array element. For example, to retrieve the ``handler_two`` handler::
868
900
869
901
.. configuration-block ::
870
902
903
+ .. code-block :: php-attributes
904
+
905
+ // src/HandlerCollection.php
906
+ namespace App;
907
+
908
+ use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
909
+
910
+ class HandlerCollection
911
+ {
912
+ public function __construct(
913
+ #[TaggedIterator('app.handler', defaultIndexMethod: 'getIndex')]
914
+ iterable $handlers
915
+ ) {
916
+ }
917
+ }
918
+
871
919
.. code-block :: yaml
872
920
873
921
# config/services.yaml
You can’t perform that action at this time.
0 commit comments