@@ -211,84 +211,112 @@ automatically changed to ``'.inner'``):
211211 ->args([service('.inner')]);
212212 };
213213
214- .. deprecated :: 6.3
214+ When decorating a service, the original service (e.g. ``App\Mailer ``) is available
215+ inside the decorating service (e.g. ``App\DecoratingMailer ``) using an ID constructed
216+ as "Decorating service ID" + the ``.inner `` suffix (e.g. in the previous example,
217+ the ID is ``'App\DecoratingMailer.inner' ``). You can control the inner service
218+ name via the ``decoration_inner_name `` option:
215219
216- The ``#[MapDecorated] `` attribute is deprecated since Symfony 6.3.
217- Instead, use the
218- :class: `#[AutowireDecorated] <Symfony\\ Component\\ DependencyInjection\\ Attribute\\ AutowireDecorated> ` attribute.
220+ .. configuration-block ::
219221
220- .. note ::
222+ .. code-block :: php-attributes
221223
222- The visibility of the decorated ``App\Mailer `` service (which is an alias
223- for the new service) will still be the same as the original ``App\Mailer ``
224- visibility.
224+ // when using the #[AutowireDecorated] attribute, you can name the argument
225+ // that holds the decorated service however you like, without needing to
226+ // configure that name explicitly
227+ #[AutowireDecorated] private Mailer $originalMailer,
225228
226- .. note ::
229+ .. code-block :: yaml
227230
228- All custom :doc: `service tags </service_container/tags >` from the decorated
229- service are removed in the new service. Only certain built-in service tags
230- defined by Symfony are retained: ``container.service_locator ``, ``container.service_subscriber ``,
231- ``kernel.event_subscriber ``, ``kernel.event_listener ``, ``kernel.locale_aware ``,
232- and ``kernel.reset ``.
231+ # config/services.yaml
232+ services :
233+ App\DecoratingMailer :
234+ # ...
235+ decoration_inner_name : ' original_mailer'
236+ arguments : ['@original_mailer']
233237
234- .. note ::
238+ # if you decorate a lot of services, consider adding the full
239+ # original service ID as part of the new ID
240+ decoration_inner_name : ' App\Mailer.original'
241+ arguments : ['@App\Mailer.original']
235242
236- The generated inner id is based on the id of the decorator service
237- (``App\DecoratingMailer `` here), not of the decorated service (``App\Mailer ``
238- here). You can control the inner service name via the ``decoration_inner_name ``
239- option:
243+ .. code-block :: xml
240244
241- .. configuration-block ::
245+ <!-- config/services.xml -->
246+ <?xml version =" 1.0" encoding =" UTF-8" ?>
247+ <container xmlns =" http://symfony.com/schema/dic/services"
248+ xmlns : xsd =" http://www.w3.org/2001/XMLSchema-instance"
249+ xsd : schemaLocation =" http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd" >
242250
243- .. code-block :: yaml
251+ <services >
252+ <!-- ... -->
244253
245- # config/services.yaml
246- services :
247- App\DecoratingMailer :
248- # ...
249- decoration_inner_name : App\DecoratingMailer.wooz
250- arguments : ['@App\DecoratingMailer.wooz']
254+ <service
255+ id =" App\DecoratingMailer"
256+ decorates =" App\Mailer"
257+ decoration-inner-name =" original_mailer"
258+ public =" false"
259+ >
260+ <argument type =" service" id =" original_mailer" />
261+ </service >
251262
252- .. code-block :: xml
263+ <!-- if you decorate a lot of services, consider adding the full
264+ original service ID as part of the new ID -->
265+ <service
266+ id =" App\DecoratingMailer"
267+ decorates =" App\Mailer"
268+ decoration-inner-name =" App\Mailer.original"
269+ public =" false"
270+ >
271+ <argument type =" service" id =" App\Mailer.original" />
272+ </service >
253273
254- <!-- config/services.xml -->
255- <?xml version =" 1.0" encoding =" UTF-8" ?>
256- <container xmlns =" http://symfony.com/schema/dic/services"
257- xmlns : xsd =" http://www.w3.org/2001/XMLSchema-instance"
258- xsd : schemaLocation =" http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd" >
259-
260- <services >
261- <!-- ... -->
262-
263- <service
264- id =" App\DecoratingMailer"
265- decorates =" App\Mailer"
266- decoration-inner-name =" App\DecoratingMailer.wooz"
267- public =" false"
268- >
269- <argument type =" service" id =" App\DecoratingMailer.wooz" />
270- </service >
274+ </services >
275+ </container >
271276
272- </services >
273- </container >
277+ .. code-block :: php
274278
275- .. code-block :: php
279+ // config/services.php
280+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
276281
277- // config/services.php
278- namespace Symfony\Component\DependencyInjection\Loader\Configurator ;
282+ use App\DecoratingMailer;
283+ use App\Mailer ;
279284
280- use App\DecoratingMailer;
281- use App\Mailer ;
285+ return function(ContainerConfigurator $container): void {
286+ $services = $container->services() ;
282287
283- return function(ContainerConfigurator $container): void {
284- $services = $container->services();
288+ $services->set(Mailer::class);
285289
286- $services->set(Mailer::class);
290+ $services->set(DecoratingMailer::class)
291+ ->decorate(Mailer::class, 'original_mailer')
292+ ->args([service('original_mailer')]);
287293
288- $services->set(DecoratingMailer::class)
289- ->decorate(Mailer::class, DecoratingMailer::class.'.wooz')
290- ->args([service(DecoratingMailer::class.'.wooz')]);
291- };
294+ // if you decorate a lot of services, consider adding the full
295+ // original service ID as part of the new ID
296+ $services->set(DecoratingMailer::class)
297+ ->decorate(Mailer::class, DecoratingMailer::class.'.original')
298+ ->args([service(DecoratingMailer::class.'.original')]);
299+ };
300+
301+ .. deprecated :: 6.3
302+
303+ The ``#[MapDecorated] `` attribute is deprecated since Symfony 6.3.
304+ Instead, use the
305+ :class: `#[AutowireDecorated] <Symfony\\ Component\\ DependencyInjection\\ Attribute\\ AutowireDecorated> ` attribute.
306+
307+ .. note ::
308+
309+ The visibility of the decorated ``App\Mailer `` service (which is an alias
310+ for the new service) will still be the same as the original ``App\Mailer ``
311+ visibility.
312+
313+ .. note ::
314+
315+ All custom :doc: `service tags </service_container/tags >` from the decorated
316+ service are removed in the new service. Only certain built-in service tags
317+ defined by Symfony are retained: ``container.service_locator ``, ``container.service_subscriber ``,
318+ ``kernel.event_subscriber ``, ``kernel.event_listener ``, ``kernel.locale_aware ``,
319+ and ``kernel.reset ``.
292320
293321Decoration Priority
294322-------------------
0 commit comments