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

Commit2aa3b65

Browse files
committed
[DependencyInjection] add AsDecorator class attribute and InnerService parameter attribute
1 parentb94166f commit2aa3b65

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

‎service_container/service_decoration.rst‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ but keeps a reference of the old one as ``.inner``:
6262

6363
..configuration-block::
6464

65+
..code-block::php-attributes
66+
67+
// src/DecoratingMailer.php
68+
namespace App;
69+
70+
// ...
71+
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
72+
73+
#[AsDecorator(decorates: Mailer::class)]
74+
class DecoratingMailer
75+
{
76+
// ...
77+
}
78+
6579
..code-block::yaml
6680
6781
# config/services.yaml
@@ -125,6 +139,28 @@ automatically changed to ``'.inner'``):
125139

126140
..configuration-block::
127141

142+
..code-block::php-attributes
143+
144+
// src/DecoratingMailer.php
145+
namespace App;
146+
147+
// ...
148+
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
149+
use Symfony\Component\DependencyInjection\Attribute\InnerService;
150+
151+
#[AsDecorator(decorates: Mailer::class)]
152+
class DecoratingMailer
153+
{
154+
private $inner;
155+
156+
public function __construct(#[InnerService] $inner)
157+
{
158+
$this->inner = $inner;
159+
}
160+
161+
// ...
162+
}
163+
128164
..code-block::yaml
129165
130166
# config/services.yaml
@@ -249,6 +285,37 @@ the ``decoration_priority`` option. Its value is an integer that defaults to
249285

250286
..configuration-block::
251287

288+
..code-block::php-attributes
289+
290+
// ...
291+
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
292+
use Symfony\Component\DependencyInjection\Attribute\InnerService;
293+
294+
#[AsDecorator(decorates: Foo::class, priority: 5)]
295+
class Bar
296+
{
297+
private $inner;
298+
299+
public function __construct(#[InnerService] $inner)
300+
{
301+
$this->inner = $inner;
302+
}
303+
// ...
304+
}
305+
306+
#[AsDecorator(decorates: Foo::class, priority: 1)]
307+
class Baz
308+
{
309+
private $inner;
310+
311+
public function __construct(#[InnerService] $inner)
312+
{
313+
$this->inner = $inner;
314+
}
315+
316+
// ...
317+
}
318+
252319
..code-block::yaml
253320
254321
# config/services.yaml
@@ -324,6 +391,26 @@ Three different behaviors are available:
324391

325392
..configuration-block::
326393

394+
..code-block::php-attributes
395+
396+
// ...
397+
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
398+
use Symfony\Component\DependencyInjection\Attribute\InnerService;
399+
use Symfony\Component\DependencyInjection\ContainerInterface;
400+
401+
#[AsDecorator(decorates: Mailer::class, onInvalid: ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]
402+
class Bar
403+
{
404+
private $inner;
405+
406+
public function __construct(#[InnerService] $inner)
407+
{
408+
$this->inner = $inner;
409+
}
410+
411+
// ...
412+
}
413+
327414
..code-block::yaml
328415
329416
# config/services.yaml

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp