Skip to content

Commit a1eb47f

Browse files
[Contracts][DependencyInjection] Add ServiceCollectionInterface
1 parent 0b70c22 commit a1eb47f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

service_container/service_subscribers_locators.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,30 @@ in the service subscriber::
111111
can also manually add the ``container.service_subscriber`` tag.
112112

113113
The injected service is an instance of :class:`Symfony\\Component\\DependencyInjection\\ServiceLocator`
114-
which implements both the PSR-11 ``ContainerInterface`` and :class:`Symfony\\Contracts\\Service\\ServiceProviderInterface`.
115-
It is also a callable and a countable::
114+
which implements the PSR-11 ``ContainerInterface``, the
115+
:class:`Symfony\\Contracts\\Service\\ServiceProviderInterface` and the
116+
:class:`Symfony\\Contracts\\Service\\ServiceCollectionInterface`. Because of
117+
this, the locator is callable, countable and traversable::
116118

117119
// ...
118120
$numberOfHandlers = count($this->locator);
119121
$nameOfHandlers = array_keys($this->locator->getProvidedServices());
122+
123+
// you can iterate through all services of the locator
124+
foreach ($this->locator as $serviceId => $service) {
125+
// do something with the service, the service id or both
126+
}
127+
120128
// ...
121129
$handler = ($this->locator)($commandClass);
122130

123131
return $handler->handle($command);
124132

133+
.. versionadded:: 7.1
134+
135+
The :class:`Symfony\\Contracts\\Service\\ServiceCollectionInterface`
136+
was introduced in Symfony 7.1.
137+
125138
Including Services
126139
------------------
127140

0 commit comments

Comments
 (0)