Closed
Description
Description
It would be nice to handle decorations on non existent services by either throwing the service not found exception or just silently ignoring the service all together, similar to how missing services as parameters are handles.
Example
Imagine having an OptionalBundle
with a service OptionalBundle\Services\OptionalService
and another Bundle DecoratorBundle
that has to decorate the OptionalService
if present:
<service id="OptionalBundle\Services\OptionalService" class="OptionalBundle\Services\OptionalService" />
<!-- ... -->
<service id="DecoratorBundle\Service\Decorator\OptionalServiceDecorator" decorates="OptionalBundle\Services\OptionalService" class="DecoratorBundle\Service\Decorator\OptionalServiceDecorator" on-invalid="ignore" />
Now in my example I don't have OptionalBundle
installed and the DecoratorBundle
would be broken. With the new attribute on-invalid
with values exception
, ignore
, null
you can control the handling:
exception
: default, throw exceptionignore
: don't create decoration service at allnull
: create decoration service but ifservice.inner
gets passed as a parameter it will be null -> might need expliciton-invalid
attribute on parameter itself.
For YAML declaration I would suggest using the @?
syntax as for arguments.