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

Commit5868190

Browse files
committed
Documented the ability of define service decoration priority
1 parent889db17 commit5868190

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

‎components/dependency_injection/advanced.rst

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,79 @@ You can change the inner service name if you want to:
219219
->setPublic(false)
220220
->setDecoratedService('foo', 'bar.wooz');
221221
222+
..versionadded::2.8
223+
The ability to define the decoration priority was introduced in Symfony 2.8.
224+
Prior to Symfony 2.8, the priority depends on the order in
225+
which definitions are found.
226+
227+
If you want to apply more than one decorator to a service, you can control their
228+
order by configuring the priority of decoration, this can be any integer number
229+
(decorators with higher priorities will be applied first).
230+
231+
..configuration-block::
232+
233+
..code-block::yaml
234+
235+
foo:
236+
class:Foo
237+
238+
bar:
239+
class:Bar
240+
public:false
241+
decorates:foo
242+
decoration_priority:5
243+
arguments:['@bar.inner']
244+
245+
baz:
246+
class:Baz
247+
public:false
248+
decorates:foo
249+
decoration_priority:1
250+
arguments:['@baz.inner']
251+
252+
..code-block::xml
253+
254+
<?xml version="1.0" encoding="UTF-8" ?>
255+
256+
<containerxmlns="http://symfony.com/schema/dic/services"
257+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
258+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
259+
260+
<services>
261+
<serviceid="foo"class="Foo" />
262+
263+
<serviceid="bar"class="Bar"decorates="foo"decoration-priority="5"public="false">
264+
<argumenttype="service"id="bar.inner" />
265+
</service>
266+
267+
<serviceid="baz"class="Baz"decorates="foo"decoration-priority="1"public="false">
268+
<argumenttype="service"id="baz.inner" />
269+
</service>
270+
</services>
271+
</container>
272+
273+
..code-block::php
274+
275+
use Symfony\Component\DependencyInjection\Reference;
276+
277+
$container->register('foo', 'Foo')
278+
279+
$container->register('bar', 'Bar')
280+
->addArgument(new Reference('bar.inner'))
281+
->setPublic(false)
282+
->setDecoratedService('foo', null, 5);
283+
284+
$container->register('baz', 'Baz')
285+
->addArgument(new Reference('baz.inner'))
286+
->setPublic(false)
287+
->setDecoratedService('foo', null, 1);
288+
289+
The generated code will be the following:
290+
291+
..code-block::php
292+
293+
$this->services['foo'] = new Baz(new Bar(new Foo())));
294+
222295
Deprecating Services
223296
--------------------
224297

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp