services.xml
with the attribute decorates
pointing to our service we want to decorate. Next we have to add our service decorator as argument, but we append an .inner
to the end of the service to keep the old one as reference.services.xml
:getDecorated()
which has the return type of our instance.ExampleService
which extends from our AbstractExampleService
. In our service the getDecorated()
function has to throw an DecorationPatternException
because it has no decoration yet.ExampleServiceDecorator
in this example. Our decorated service has to extend from the AbstractExampleService
and the constructor has to accept an instance of AbstractExampleService
. Furthermore, the getDecorated()
function has to return the decorated service passed into the constructor.doSomethingNew()
which first calls the getDecorated()
and then our new function doSomethingNew()
because if our decorator does not implement it yet, it will call it from the parent. The advantage of adding it as normal public function is that you can implement it step by step into your other services without any issues. After you have implemented the function in every service decorator, you can make it abstract for the next release. If you add it directly as an abstract function, you will get errors because the function is required for every service decorator.