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