Allowed to define the priority of service decoration¶

Service decoration is a powerful way to replace some service without actually removing it from the container. This way the new service can make use of the replaced service.

In Symfony 2.8, when more than one service decorate another one, you can define the priority of each decorator to have a more precise control over them. The new option is called decoration_priority , its default value is 0 and the higher its value, the earlier the decorator is applied:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 services : app.service1 : class : AppBundle\Service\Service1 app.service2 : class : AppBundle\Service\Service2 arguments : [ '@app.service2.inner' ] decorates : app.service1 public : false app.service3 : class : AppBundle\Service\Service3 arguments : [ '@app.service3.inner' ] decorates : app.service1 decoration_priority : 1 public : false

In the above example, app.service3 is applied first because it defines a priority of 1 and the priority for app.service2 is 0 (the default value). Therefore, this config is equivalent to the following PHP code: