Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit beed31f

Browse filesBrowse files
committed
feature #17747 [DependencyInjection] Complete examples with #[TaggedIterator] and #[TaggedLocator] attributes (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Complete examples with `#[TaggedIterator]` and `#[TaggedLocator]` attributes Resolves #15948 Commits ------- f6c140c [DependencyInjection] Complete examples with TaggedIterator and TaggedLocator attributes
2 parents 7165fe6 + f6c140c commit beed31f
Copy full SHA for beed31f

File tree

Expand file treeCollapse file tree

2 files changed

+82
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+82
-0
lines changed

‎service_container/service_subscribers_locators.rst

Copy file name to clipboardExpand all lines: service_container/service_subscribers_locators.rst
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,23 @@ of the ``key`` tag attribute (as defined in the ``index_by`` locator option):
516516

517517
.. configuration-block::
518518

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+
519536
.. code-block:: yaml
520537
521538
# config/services.yaml
@@ -619,6 +636,23 @@ attribute to the locator service defining the name of this custom method:
619636

620637
.. configuration-block::
621638

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+
622656
.. code-block:: yaml
623657
624658
# config/services.yaml

‎service_container/tags.rst

Copy file name to clipboardExpand all lines: service_container/tags.rst
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,22 @@ you can define it in the configuration of the collecting service:
707707

708708
.. configuration-block::
709709

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+
710726
.. code-block:: yaml
711727
712728
# config/services.yaml
@@ -762,6 +778,22 @@ indexed by the ``key`` attribute:
762778

763779
.. configuration-block::
764780

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+
765797
.. code-block:: yaml
766798
767799
# config/services.yaml
@@ -868,6 +900,22 @@ array element. For example, to retrieve the ``handler_two`` handler::
868900

869901
.. configuration-block::
870902

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+
871919
.. code-block:: yaml
872920
873921
# config/services.yaml

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.