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

Update service_decoration.rst#10654

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

Closed
nclavaud wants to merge2 commits intosymfony:2.8fromnclavaud:patch-2
Closed
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
19 changes: 9 additions & 10 deletionsservice_container/service_decoration.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,7 @@
How to Decorate Services
========================

When overriding an existing definition (e.g. when applying the `Decorator pattern`_),
the original service is lost:
When overriding an existing definition, the original service is lost:

.. configuration-block::

Expand All@@ -18,7 +17,7 @@ the original service is lost:
# this replaces the old app.mailer definition with the new one, the
# old definition is lost
app.mailer:
class: AppBundle\DecoratingMailer
class: AppBundle\NewMailer

.. code-block:: xml

Expand All@@ -32,26 +31,26 @@ the original service is lost:

<!-- this replaces the old app.mailer definition with the new
one, the old definition is lost -->
<service id="app.mailer" class="AppBundle\DecoratingMailer" />
<service id="app.mailer" class="AppBundle\NewMailer" />
</services>
</container>

.. code-block:: php

use AppBundle\Mailer;
use AppBundle\DecoratingMailer;
use AppBundle\NewMailer;

$container->register('app.mailer', Mailer::class);

// this replaces the old app.mailer definition with the new one, the
// old definition is lost
$container->register('app.mailer',DecoratingMailer::class);
$container->register('app.mailer',NewMailer::class);

Most of the time, that's exactly what you want to do. But sometimes,
you might want to decorate the old one instead. In this case, the
old service should be kept around to be able to reference it in the
new one. This configuration replaces ``app.mailer`` with a new one, but keeps
a reference of the old one as ``app.decorating_mailer.inner``:
you might want to decorate the old one instead (i.e. apply the `Decorator pattern`_).
In this case, theold service should be kept around to be able to reference
it in thenew one. This configuration replaces ``app.mailer`` with a new one,
but keepsa reference of the old one as ``app.decorating_mailer.inner``:

.. configuration-block::

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp