Skip to content

[DI] Handling decorations on non existent services #33522

Closed
@pascalheidmann-bedarf

Description

@pascalheidmann-bedarf

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 exception
  • ignore: don't create decoration service at all
  • null: create decoration service but if service.inner gets passed as a parameter it will be null -> might need explicit on-invalid attribute on parameter itself.

For YAML declaration I would suggest using the @? syntax as for arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions