Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8d35db9

Browse files
committedApr 1, 2025·
Tweaks
1 parent 05ecf73 commit 8d35db9

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed
 

Diff for: ‎service_container/service_subscribers_locators.rst

+12-11
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ This is done by having ``getSubscribedServices()`` return an array of
298298
The above example requires using ``3.2`` version or newer of ``symfony/service-contracts``.
299299

300300
.. _service-locator_autowire-locator:
301-
.. _service-locator_autowire-iterator:
301+
.. _the-autowirelocator-and-autowireiterator-attributes:
302302

303-
The AutowireLocator and AutowireIterator Attributes
304-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
303+
The AutowireLocator Attribute
304+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305305

306306
Another way to define a service locator is to use the
307307
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\AutowireLocator`
@@ -381,16 +381,17 @@ attribute::
381381
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\AutowireLocator`
382382
attribute was introduced in Symfony 6.4.
383383

384+
.. _service-locator_autowire-iterator:
385+
384386
The AutowireIterator Attribute
385387
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
386-
Variant of the ``AutowireLocator`` that specifically provides an iterable of services
387-
based on a tag. This allows you to collect all services with a particular tag into
388-
an iterable, which can be useful when you need to iterate over a set of services
389-
rather than retrieving them individually.
390388

391-
For example, if you want to collect all the handlers for different command types,
392-
you can use the ``AutowireIterator`` attribute to automatically inject all services
393-
tagged with a specific tag::
389+
A variant of ``AutowireLocator`` that injects an iterable of services tagged
390+
with a specific :doc:`tag </service_container/tags>`. This is useful to loop
391+
over a set of tagged services instead of retrieving them individually.
392+
393+
For example, to collect all handlers for different command types, use the
394+
``AutowireIterator`` attribute and pass the tag used by those services::
394395

395396
// src/CommandBus.php
396397
namespace App;
@@ -404,7 +405,7 @@ tagged with a specific tag::
404405
{
405406
public function __construct(
406407
#[AutowireIterator('command_handler')]
407-
private iterable $handlers, // Collects all services tagged with 'command_handler'
408+
private iterable $handlers, // collects all services tagged with 'command_handler'
408409
) {
409410
}
410411

0 commit comments

Comments
 (0)
Please sign in to comment.