Skip to content

Commit 3bbf43a

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

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

service_container/service_subscribers_locators.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ It is also a callable and a countable::
122122

123123
return $handler->handle($command);
124124

125+
Because the service locator implements the
126+
:class:`Symfony\\Contracts\\Service\\ServiceCollectionInterface`, it is also
127+
a ``\Traversable``. This allows to iterate through all registered services to
128+
apply some operations on them::
129+
130+
foreach ($this->locator as $serviceId => $service) {
131+
// access to the service directly
132+
$service->someMethod();
133+
134+
// or via the `get()` method
135+
$this->locator->get($serviceId)->someMethod();
136+
}
137+
138+
.. versionadded:: 7.1
139+
140+
The :class:`Symfony\\Contracts\\Service\\ServiceCollectionInterface`
141+
was introduced in Symfony 7.1.
142+
125143
Including Services
126144
------------------
127145

0 commit comments

Comments
 (0)