4
4
How to Decorate Services
5
5
========================
6
6
7
- When overriding an existing definition (e.g. when applying the `Decorator pattern `_),
8
- the original service is lost:
7
+ When overriding an existing definition, the original service is lost:
9
8
10
9
.. configuration-block ::
11
10
@@ -18,7 +17,7 @@ the original service is lost:
18
17
# this replaces the old app.mailer definition with the new one, the
19
18
# old definition is lost
20
19
app.mailer :
21
- class : AppBundle\DecoratingMailer
20
+ class : AppBundle\NewMailer
22
21
23
22
.. code-block :: xml
24
23
@@ -32,26 +31,26 @@ the original service is lost:
32
31
33
32
<!-- this replaces the old app.mailer definition with the new
34
33
one, the old definition is lost -->
35
- <service id =" app.mailer" class =" AppBundle\DecoratingMailer " />
34
+ <service id =" app.mailer" class =" AppBundle\NewMailer " />
36
35
</services >
37
36
</container >
38
37
39
38
.. code-block :: php
40
39
41
40
use AppBundle\Mailer;
42
- use AppBundle\DecoratingMailer ;
41
+ use AppBundle\NewMailer ;
43
42
44
43
$container->register('app.mailer', Mailer::class);
45
44
46
45
// this replaces the old app.mailer definition with the new one, the
47
46
// old definition is lost
48
- $container->register('app.mailer', DecoratingMailer ::class);
47
+ $container->register('app.mailer', NewMailer ::class);
49
48
50
49
Most of the time, that's exactly what you want to do. But sometimes,
51
- you might want to decorate the old one instead. In this case, the
52
- old service should be kept around to be able to reference it in the
53
- new one. This configuration replaces ``app.mailer `` with a new one, but keeps
54
- a reference of the old one as ``app.decorating_mailer.inner ``:
50
+ you might want to decorate the old one instead (i.e. apply the ` Decorator pattern `_).
51
+ In this case, the old service should be kept around to be able to reference
52
+ it in the new one. This configuration replaces ``app.mailer `` with a new one,
53
+ but keeps a reference of the old one as ``app.decorating_mailer.inner ``:
55
54
56
55
.. configuration-block ::
57
56
0 commit comments