Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Reword
  • Loading branch information
javiereguiluz committed Sep 23, 2019
commit 8d8c65e7ceb64e6a913e17a45175719d4b65e439
18 changes: 12 additions & 6 deletions service_container/service_subscribers_locators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ Defining a Service Locator

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

.. configuration-block::

Expand All @@ -259,6 +258,9 @@ there is no id specified for the service it will inherit its external id.
-
App\FooCommand: '@app.command_handler.foo'
App\BarCommand: '@app.command_handler.bar'
# if the element has no key, the ID of the original service is used
'@app.command_handler.baz'

# if you are not using the default service autoconfiguration,
# add the following tag to the service definition:
# tags: ['container.service_locator']
Expand All @@ -275,8 +277,10 @@ there is no id specified for the service it will inherit its external id.

<service id="app.command_handler_locator" class="Symfony\Component\DependencyInjection\ServiceLocator">
<argument type="collection">
<argument key="App\FooCommand" type="service" id="app.command_handler.foo"/>
<argument key="App\BarCommand" type="service" id="app.command_handler.bar"/>
<argument key="App\FooCommand" type="service" id="app.command_handler.foo" />
<argument key="App\BarCommand" type="service" id="app.command_handler.bar" />
<!-- if the element has no key, the ID of the original service is used -->
<argument type="service" id="app.command_handler.baz" />
</argument>
<!--
if you are not using the default service autoconfiguration,
Expand All @@ -301,7 +305,9 @@ there is no id specified for the service it will inherit its external id.
->setArguments([[
'App\FooCommand' => new Reference('app.command_handler.foo'),
'App\BarCommand' => new Reference('app.command_handler.bar'),
]])
// if the element has no key, the ID of the original service is used
new Reference('app.command_handler.baz'),
)))
// if you are not using the default service autoconfiguration,
// add the following tag to the service definition:
// ->addTag('container.service_locator')
Expand All @@ -314,7 +320,7 @@ there is no id specified for the service it will inherit its external id.

.. versionadded:: 4.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a blank line after the directive


The ability to add services without specifying an id was introduced in
The ability to add services without specifying their id was introduced in
Symfony 4.2.

.. note::
Expand Down