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 8d35db9

Browse filesBrowse files
committed
Tweaks
1 parent 05ecf73 commit 8d35db9
Copy full SHA for 8d35db9

File tree

Expand file treeCollapse file tree

1 file changed

+12
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-11
lines changed

‎service_container/service_subscribers_locators.rst

Copy file name to clipboardExpand all lines: service_container/service_subscribers_locators.rst
+12-11Lines changed: 12 additions & 11 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.