-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Handling decorations on non existent services #33522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
DependencyInjection
Feature
Help wanted
Issues and PRs which are looking for volunteers to complete them.
Comments
Just an idea:
|
That would make sense to me. Anyone for giving it a try? |
Yes I'll :) |
fabpot
added a commit
that referenced
this issue
Nov 3, 2019
…non existent decorated services (mtarld) This PR was merged into the 4.4 branch. Discussion ---------- [DI] Add ability to choose behavior of decorations on non existent decorated services | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #33522 | License | MIT | Doc PR | symfony/symfony-docs#12442 # Handling decorations on non existent decorated services Handle decorations on non existent decorated services by either throwing the service not found exception, silently ignoring services (decorator & decorated) all together or leave the decorated service to null (current behavior) Something almost similar to how missing services as parameters are handles. ## Yaml configuration ```yaml decorator: decorates: decorated decoration_on_invalid: ignore ``` Available values: `exception`, `ignore`, `null`. `exception` if nothing is specified. ## Xml configuration ```xml <service id="decorator" decorates="decorated" decoration-on-invalid="ignore" /> ``` Available values: `exception`, `ignore`, `null`. `exception` if nothing is specified. ## Behavior - `exception`: Throws a `ServiceNotFoundException` telling that the decorator's dependency is missing - `ignore`: Remove decorator definition. Decorator and decorated will not be available at all. - `null`: Keep decorator but set decorated to null. Therefore, decorator `__construct` should be written with a nullable decorated dependency (`public function __contruct(?DecoratedInterface $decorated) {}`) and check should be done in other methods Commits ------- f167c77 Handle non existent decorated services
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
DependencyInjection
Feature
Help wanted
Issues and PRs which are looking for volunteers to complete them.
Uh oh!
There was an error while loading. Please reload this page.
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 serviceOptionalBundle\Services\OptionalService
and another BundleDecoratorBundle
that has to decorate theOptionalService
if present:Now in my example I don't have
OptionalBundle
installed and theDecoratorBundle
would be broken. With the new attributeon-invalid
with valuesexception
,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.The text was updated successfully, but these errors were encountered: