Quantcast
Channel: Symfony Blog
Viewing all articles
Browse latest Browse all 3058

New in Symfony 5.1: Simpler service decoration

$
0
0
Nicolas Grekas

Contributed by
Nicolas Grekas
in #36389.

Service decoration is used in Symfony applications to change the behavior of some service without replacing it entirely. To do that, you need to inject the original service as an argument of the new decorating service. The problem is that the original service no longer exists, so you can't use its original ID.

In previous Symfony versions you needed to use the syntax decorating service ID + .inner to refer to that service. This quickly becomes cumbersome in YAML/XML when using PHP classes as service IDs. That's why in Symfony 5.1 we've simplified this feature to always use .inner to refer to the original service:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# config/services.yamlservices:App\Mailer:~# BeforeApp\SpecialMailer:decorates:App\Mailerarguments:['@App\SpecialMailer.inner']# AfterApp\SpecialMailer:decorates:App\Mailerarguments:['@.inner']

Sponsor the Symfony project.

Viewing all articles
Browse latest Browse all 3058

Trending Articles