Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[DependencyInjection] Add documentation for service locator changes#10397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 2 commits intosymfony:4.3fromcodedmonkey:master
Sep 23, 2019
Merged
Changes fromall commits
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
27 changes: 22 additions & 5 deletionsservice_container/service_subscribers_locators.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,8 +243,8 @@ Defining a Service Locator
--------------------------

To manually define a service locator, create a new service definition and add
the ``container.service_locator`` tag to it. Useits ``arguments`` option to
include as manyservicesas needed in it.
the ``container.service_locator`` tag to it. Usethe first argument of the
service definition to pass a collection ofservicesto the service locator:

.. configuration-block::

Expand All@@ -258,6 +258,9 @@ include as many services as needed in it.
-
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@@ -274,8 +277,10 @@ include as many services as needed in it.

<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@@ -300,12 +305,24 @@ include as many services as needed in it.
->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')
;

.. versionadded:: 4.1
The service locator autoconfiguration was introduced in Symfony 4.1. In
previous Symfony versions you always needed to add the
``container.service_locator`` tag explicitly.

.. 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 their id was introduced in
Symfony 4.2.

.. note::

The services defined in the service locator argument must include keys,
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp