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] Documented the ability of define the service decoration priority#5600

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
xabbuh merged 1 commit intosymfony:2.8fromdosten:dependency-injection/service-decoration-priority
Jan 13, 2016
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
73 changes: 73 additions & 0 deletionscomponents/dependency_injection/advanced.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -219,6 +219,79 @@ You can change the inner service name if you want to:
->setPublic(false)
->setDecoratedService('foo', 'bar.wooz');

.. versionadded:: 2.8
The ability to define the decoration priority was introduced in Symfony 2.8.
Prior to Symfony 2.8, the priority depends on the order in
which definitions are found.

If you want to apply more than one decorator to a service, you can control their
order by configuring the priority of decoration, this can be any integer number
(decorators with higher priorities will be applied first).

.. configuration-block::

.. code-block:: yaml

foo:
class: Foo

bar:
class: Bar
public: false
decorates: foo
decoration_priority: 5
arguments: ['@bar.inner']

baz:
class: Baz
public: false
decorates: foo
decoration_priority: 1
arguments: ['@baz.inner']

.. code-block:: 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>
<service id="foo" class="Foo" />

<service id="bar" class="Bar" decorates="foo" decoration-priority="5" public="false">
<argument type="service" id="bar.inner" />
</service>

<service id="baz" class="Baz" decorates="foo" decoration-priority="1" public="false">
<argument type="service" id="baz.inner" />
</service>
</services>
</container>

.. code-block:: php

use Symfony\Component\DependencyInjection\Reference;

$container->register('foo', 'Foo')

$container->register('bar', 'Bar')
->addArgument(new Reference('bar.inner'))
->setPublic(false)
->setDecoratedService('foo', null, 5);

$container->register('baz', 'Baz')
->addArgument(new Reference('baz.inner'))
->setPublic(false)
->setDecoratedService('foo', null, 1);

The generated code will be the following:

.. code-block:: php

$this->services['foo'] = new Baz(new Bar(new Foo())));

Deprecating Services
--------------------

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp