Skip to content

Commit 8d8c65e

Browse files
committed
Reword
1 parent bc5ef85 commit 8d8c65e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

service_container/service_subscribers_locators.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ Defining a Service Locator
244244

245245
To manually define a service locator, create a new service definition and add
246246
the ``container.service_locator`` tag to it. Use the first argument of the
247-
service definition to pass a collection of services to the service locator. If
248-
there is no id specified for the service it will inherit its external id.
247+
service definition to pass a collection of services to the service locator:
249248

250249
.. configuration-block::
251250

@@ -259,6 +258,9 @@ there is no id specified for the service it will inherit its external id.
259258
-
260259
App\FooCommand: '@app.command_handler.foo'
261260
App\BarCommand: '@app.command_handler.bar'
261+
# if the element has no key, the ID of the original service is used
262+
'@app.command_handler.baz'
263+
262264
# if you are not using the default service autoconfiguration,
263265
# add the following tag to the service definition:
264266
# tags: ['container.service_locator']
@@ -275,8 +277,10 @@ there is no id specified for the service it will inherit its external id.
275277
276278
<service id="app.command_handler_locator" class="Symfony\Component\DependencyInjection\ServiceLocator">
277279
<argument type="collection">
278-
<argument key="App\FooCommand" type="service" id="app.command_handler.foo"/>
279-
<argument key="App\BarCommand" type="service" id="app.command_handler.bar"/>
280+
<argument key="App\FooCommand" type="service" id="app.command_handler.foo" />
281+
<argument key="App\BarCommand" type="service" id="app.command_handler.bar" />
282+
<!-- if the element has no key, the ID of the original service is used -->
283+
<argument type="service" id="app.command_handler.baz" />
280284
</argument>
281285
<!--
282286
if you are not using the default service autoconfiguration,
@@ -301,7 +305,9 @@ there is no id specified for the service it will inherit its external id.
301305
->setArguments([[
302306
'App\FooCommand' => new Reference('app.command_handler.foo'),
303307
'App\BarCommand' => new Reference('app.command_handler.bar'),
304-
]])
308+
// if the element has no key, the ID of the original service is used
309+
new Reference('app.command_handler.baz'),
310+
)))
305311
// if you are not using the default service autoconfiguration,
306312
// add the following tag to the service definition:
307313
// ->addTag('container.service_locator')
@@ -314,7 +320,7 @@ there is no id specified for the service it will inherit its external id.
314320

315321
.. versionadded:: 4.2
316322

317-
The ability to add services without specifying an id was introduced in
323+
The ability to add services without specifying their id was introduced in
318324
Symfony 4.2.
319325

320326
.. note::

0 commit comments

Comments
 (0)