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

Add section about anonymous services in YAML#10041

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 1 commit intosymfony:3.4fromcodedmonkey:fix_7694
Jul 11, 2018
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
87 changes: 69 additions & 18 deletionsservice_container/alias_private.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ Anonymous Services

.. note::

Anonymous services are only supported by the XML configurationformat.
Anonymous services are only supported by the XMLand YAMLconfigurationformats.

In some cases, you may want to prevent a service being used as a dependency of
other services. This can be achieved by creating an anonymous service. These
Expand All@@ -158,23 +158,74 @@ created where they are used.

The following example shows how to inject an anonymous service into another service:

.. code-block:: xml
.. configuration-block::

.. code-block:: yaml

# app/config/services.yml
services:
_defaults:
autowire: true

AppBundle\Foo:
arguments:
- !service
class: AppBundle\AnonymousBar
autowire: true
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed given that the default for this file istrue too?


.. code-block:: xml

<!-- app/config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<defaults autowire="true" />

<service id="foo" class="AppBundle\Foo">
<argument type="service">
<service class="AppBundle\AnonymousBar" />
</argument>
</service>
</services>
</container>

<!-- app/config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">
Using an anonymous service as a factory looks like this:

<services>
<service id="foo" class="AppBundle\Foo">
<argument type="service">
<service class="AppBundle\AnonymousBar" />
</argument>
</service>
</services>
</container>
.. configuration-block::

.. code-block:: yaml

# app/config/services.yml
services:
_defaults:
autowire: true

AppBundle\Foo:
factory: [ !service { class: AppBundle\FooFactory }, 'constructFoo' ]

.. code-block:: xml

<!-- app/config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<defaults autowire="true" />

<service id="foo" class="AppBundle\Foo">
<factory method="constructFoo">
<service class="App\FooFactory"/>
</factory>
</service>
</services>
</container>

Deprecating Services
--------------------
Expand All@@ -186,8 +237,8 @@ or you decided not to maintain it anymore), you can deprecate its definition:

.. code-block:: yaml

AppBundle\Service\OldService:
deprecated: The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0.
AppBundle\Service\OldService:
deprecated: The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0.

.. code-block:: xml

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp