Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DependencyInjection] add AsDecorator class attribute and InnerService parameter attribute#45834
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedMar 24, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the PR. I see several issues with the current approach:
Instead of adding a new pass, I think the attributes should be looked for in AutowirePass, where there is already some logic that deals with decoration. This would fix all listed issues I believe. |
src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Compiler/RegisterDecoratorAttributesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Compiler/RegisterDecoratorAttributesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Compiler/RegisterDecoratorAttributesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Compiler/RegisterDecoratorAttributesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas commentedApr 11, 2022
(please mind the PR title+description also ;)) |
Jean-Beru commentedApr 14, 2022
Thanks for your reviews ! Code and description have been updated :) |
nicolas-grekas left a comment
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.
LGTM. Can you please confirm that you ran this on a small project and that it worked as expected?
dunglas left a comment
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.
👍
Jean-Beru commentedApr 15, 2022 • edited by nicolas-grekas
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by nicolas-grekas
Uh oh!
There was an error while loading.Please reload this page.
I tried from a new demo application with : finalclass Fooimplements FooInterface{publicfunction__invoke():string {return'new'.__CLASS__.'()'; }}#[AsDecorator(decorates: Foo::class, decorationPriority:10)]finalclass Bar10implements FooInterface{privateFooInterface$foo;publicfunction__construct(#[InnerService]FooInterface$foo) {$this->foo =$foo; }publicfunction__invoke():string {return'new'.__CLASS__.'('.($this->foo)().')'; }}#[AsDecorator(decorates: Foo::class, decorationPriority:20)]finalclass Bar20implements FooInterface{privateFooInterface$foo;publicfunction__construct(#[InnerServicce]FooInterface$foo) {$this->foo =$foo; }publicfunction__invoke():string {return'new'.__CLASS__.'('.($this->foo)().')'; }}#[AsController]class TestController{privateFooInterface$foo;publicfunction__construct(#[Autowire(service: Foo::class)]FooInterface$foo) {$this->foo =$foo; } #[Route('/test/')]publicfunctionindex():Response {returnnewResponse(($this->foo)()); }} Calling |
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Thanks! I'm just bike-shedding on the naming, WDYT?
Esp Inner vs DecoratedService? (or just Decorated)?
Any opinion @symfony/mergers? (see#45834 (comment) for examples)
src/Symfony/Component/DependencyInjection/Attribute/AsDecorator.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
…e parameter attribute
c0c5468 tod8a4680Comparenicolas-grekas commentedApr 19, 2022
Thank you@Jean-Beru. |
…apDecorated]` (chalasr)This PR was merged into the 6.1 branch.Discussion----------[DependencyInjection] Rename `#[InnerService]` to `#[MapDecorated]`| Q | A| ------------- | ---| Branch? | 6.1| Bug fix? | no| New feature? | no but tweaks one#45834| Deprecations? | no| Tickets | -| License | MIT| Doc PR | -When talking about the decorator pattern outside of Symfony, the term `inner` is pretty much (if not totally) inexistent. Worse, it makes the concept harder to explain. Take "there is a decorator and a decorated object" vs "there is a decorator and an inner object": using the later form, one has to explain both what is the decorator and what is the inner. While using the former, explaining what the decorator makes it obvious what the decorated is.I propose to take the addition of this attribute as an opportunity to start making this special term go away.Also I removed the `Service` suffix. It is tempting to keep it for explicitness, but it feels kinda redundant and AFAIK no other core attribute has such redundant suffix, maybe because their namespace is enough to indicate their target.Commits-------c0a7979 [DependencyInjection] Rename `#[InnerService]` to `#[MapDecorated]`
Uh oh!
There was an error while loading.Please reload this page.
The aim f this PR is to allow decorator declaration with PHP8 attributes by using
AsDecoratorattribute on class and, optionally,InnerServiceparameter attribute to inject decorated service.To use it :