Skip to content

Commit ed81ff5

Browse files
committed
minor symfony#10654 Update service_decoration.rst (nclavaud)
This PR was squashed before being merged into the 2.8 branch (closes symfony#10654). Discussion ---------- Update service_decoration.rst Make it clear that the first paragraph is *not* about decorating a service, but completely overriding it. Decorating is explained in the next paragraph, so the reference to the decorator pattern has been moved there. Otherwise it's easy to get confused when reading the doc. The original text was clear, but then the meaning changed when the file was moved, in commit symfony@141e922#diff-ebbbc2e2adacde7254ce22cf2a32198c <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 0386306 Update service_decoration.rst
2 parents 4310a38 + 0386306 commit ed81ff5

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

service_container/service_decoration.rst

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
How to Decorate Services
55
========================
66

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:
98

109
.. configuration-block::
1110

@@ -18,7 +17,7 @@ the original service is lost:
1817
# this replaces the old app.mailer definition with the new one, the
1918
# old definition is lost
2019
app.mailer:
21-
class: AppBundle\DecoratingMailer
20+
class: AppBundle\NewMailer
2221
2322
.. code-block:: xml
2423
@@ -32,26 +31,26 @@ the original service is lost:
3231
3332
<!-- this replaces the old app.mailer definition with the new
3433
one, the old definition is lost -->
35-
<service id="app.mailer" class="AppBundle\DecoratingMailer" />
34+
<service id="app.mailer" class="AppBundle\NewMailer" />
3635
</services>
3736
</container>
3837
3938
.. code-block:: php
4039
4140
use AppBundle\Mailer;
42-
use AppBundle\DecoratingMailer;
41+
use AppBundle\NewMailer;
4342
4443
$container->register('app.mailer', Mailer::class);
4544
4645
// this replaces the old app.mailer definition with the new one, the
4746
// old definition is lost
48-
$container->register('app.mailer', DecoratingMailer::class);
47+
$container->register('app.mailer', NewMailer::class);
4948
5049
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``:
5554

5655
.. configuration-block::
5756

0 commit comments

Comments
 (0)