-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Add ability to choose behavior of decorations on non existent decorated services #33854
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
[DI] Add ability to choose behavior of decorations on non existent decorated services #33854
Conversation
src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(FYI, I made some tweaks, esp. in ResolveInvalidReferencesPass
)
src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php
Outdated
Show resolved
Hide resolved
There is a force-push collision here, the changes from https://github.com/symfony/symfony/compare/8bee11a60198ecb0729b451165f3e6036911d7db..33098d2ba8f5fbea8229ff4fc64a6215e138ea5c are lost. Please recover them :) |
Good to go @nicolas-grekas ❓ |
Thank you @mtarld. |
…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
…ce" (mtarld) This PR was merged into the 4.4 branch. Discussion ---------- Documented "Handling decorations on non existent service" Documentation part for the PR: symfony/symfony#33854 Commits ------- cb07e30 Add "Handling decorations on non existent service"
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
Available values:
exception
,ignore
,null
.exception
if nothing is specified.Xml configuration
Available values:
exception
,ignore
,null
.exception
if nothing is specified.Behavior
exception
: Throws aServiceNotFoundException
telling that the decorator's dependency is missingignore
: 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