From 045625308a0a41cf922ca424a2a99b5f8dedac98 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 14 Apr 2020 10:54:07 +0200 Subject: [PATCH] [DI] Updated the way inner services are referrer to in decoration --- reference/configuration/framework.rst | 2 +- service_container/service_decoration.rst | 38 ++++++++++++++---------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 3c0afc31e03..caafcaf1693 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -2850,7 +2850,7 @@ Name of the lock you want to create. lock.invoice.retry_till_save.store: class: Symfony\Component\Lock\Store\RetryTillSaveStore decorates: lock.invoice.store - arguments: ['@lock.invoice.retry_till_save.store.inner', 100, 50] + arguments: ['@.inner', 100, 50] workflows ~~~~~~~~~ diff --git a/service_container/service_decoration.rst b/service_container/service_decoration.rst index 0e096955140..f4200a85d4c 100644 --- a/service_container/service_decoration.rst +++ b/service_container/service_decoration.rst @@ -58,7 +58,7 @@ Most of the time, that's exactly what you want to do. But sometimes, you might want to decorate the old one instead (i.e. apply the `Decorator pattern`_). 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\DecoratingMailer.inner``: +but keeps a reference of the old one as ``.inner``: .. configuration-block:: @@ -70,7 +70,7 @@ but keeps a reference of the old one as ``App\DecoratingMailer.inner``: App\DecoratingMailer: # overrides the App\Mailer service - # but that service is still available as App\DecoratingMailer.inner + # but that service is still available as ".inner" decorates: App\Mailer .. code-block:: xml @@ -84,6 +84,8 @@ but keeps a reference of the old one as ``App\DecoratingMailer.inner``: + @@ -106,7 +108,7 @@ but keeps a reference of the old one as ``App\DecoratingMailer.inner``: $services->set(DecoratingMailer::class) // overrides the App\Mailer service - // but that service is still available as App\DecoratingMailer.inner + // but that service is still available as ".inner" ->decorate(Mailer::class); }; @@ -119,7 +121,7 @@ decorating service has one argument type-hinted with the decorated service class If you are not using autowiring or the decorating service has more than one constructor argument type-hinted with the decorated service class, you must inject the decorated service explicitly (the ID of the decorated service is -automatically changed to ``decorating_service_id + '.inner'``): +automatically changed to ``'.inner'``): .. configuration-block:: @@ -132,7 +134,7 @@ automatically changed to ``decorating_service_id + '.inner'``): App\DecoratingMailer: decorates: App\Mailer # pass the old service as an argument - arguments: ['@App\DecoratingMailer.inner'] + arguments: ['@.inner'] .. code-block:: xml @@ -148,7 +150,7 @@ automatically changed to ``decorating_service_id + '.inner'``): - + @@ -170,9 +172,13 @@ automatically changed to ``decorating_service_id + '.inner'``): $services->set(DecoratingMailer::class) ->decorate(Mailer::class) // pass the old service as an argument - ->args([ref(DecoratingMailer::class.'.inner')]); + ->args([ref('.inner')]); }; +.. versionadded:: 5.1 + + The special ``.inner`` value was introduced in Symfony 5.1. In previous + versions you needed to use: ``decorating_service_id + '.inner'``. .. tip:: @@ -256,12 +262,12 @@ the ``decoration_priority`` option. Its value is an integer that defaults to Bar: decorates: Foo decoration_priority: 5 - arguments: ['@Bar.inner'] + arguments: ['@.inner'] Baz: decorates: Foo decoration_priority: 1 - arguments: ['@Baz.inner'] + arguments: ['@.inner'] .. code-block:: xml @@ -276,11 +282,11 @@ the ``decoration_priority`` option. Its value is an integer that defaults to - + - + @@ -297,11 +303,11 @@ the ``decoration_priority`` option. Its value is an integer that defaults to $services->set(Bar::class) ->decorate(Foo::class, null, 5) - ->args([ref(Bar::class.'.inner')]); + ->args([ref('.inner')]); $services->set(Baz::class) ->decorate(Foo::class, null, 1) - ->args([ref(Baz::class.'.inner')]); + ->args([ref('.inner')]); }; @@ -331,7 +337,7 @@ Three different behaviors are available: Bar: decorates: Foo decoration_on_invalid: ignore - arguments: ['@Bar.inner'] + arguments: ['@.inner'] .. code-block:: xml @@ -346,7 +352,7 @@ Three different behaviors are available: - + @@ -365,7 +371,7 @@ Three different behaviors are available: $services->set(Bar::class) ->decorate(Foo::class, null, 0, ContainerInterface::IGNORE_ON_INVALID_REFERENCE) - ->args([ref(Bar::class.'.inner')]) + ->args([ref('.inner')]) ; }; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy