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#[AutowireInline] attribute to allow service definition at the class level#52820
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
6ca710b toc547abcComparenicolas-grekas commentedNov 30, 2023
Thanks for proposing and for submitting! I'm wondering if we couldn't get rid of the interface and rename the proposed argument to e.g. |
DaDeather commentedDec 1, 2023
Sure I was unsure about the naming anyway though 🙈. About the interface: I'd rather see it as a benefit there allowing one to implement the interface and go for it instead of extending the base classes like the Combining the factory thing into the I made the adjustments according to your comment unless the one with the Interface. Just let me know if I still should remove it / rename it or whatever 👍. And thanks for your fast feedback on this! |
b9abcbc to48fc63bCompare
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.
I'm not convinced by the interface, I'd prefer removing it.
I'm generally not convinced by interfaces for value objects and attributes are value objects.
Extending the class makes sense to me in this case.
src/Symfony/Component/DependencyInjection/Attribute/AutowireInline.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Attribute/AutowireInline.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Attribute/AutowireInline.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Attribute/AutowireInline.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Attribute/AutowireInline.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Attribute/AutowireInline.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.
src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
48fc63b tof21a70bCompareDaDeather commentedDec 1, 2023
Alright 👍 I have removed the interface and based the |
f21a70b to917a698Comparesrc/Symfony/Component/DependencyInjection/Attribute/AutowireInline.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
stof commentedDec 1, 2023 • 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.
Please update the PR description to show usages of the feature. This makes it a lot easier for the documentation team (and also for reviewers) |
917a698 to86b2806Compare5955b18 to6a7e3fcComparenicolas-grekas commentedFeb 27, 2024
About my remaining concerns ( WDYT? Up to give it a try? |
DaDeather commentedMar 6, 2024
Sure! Would you expect a definition be like this: class AutowireInlineAttributesBar {publicfunction__construct(Foo$foo,string$someString) { }}class AutowireInlineAttributes{publicfunction__construct( #[AutowireInline(AutowireInlineAttributesBar::class, ['$foo' => Foo::class,'$someString' =>'testString', ])]publicAutowireInlineAttributesBar$inlined, ) { }} Where the class Besides that if I got you right I would have to create a class called Is this assumption correct? |
nicolas-grekas commentedMar 6, 2024
You've got it right I think :) |
DaDeather commentedMar 7, 2024 • 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.
I've prepared something that doesn't quite work 🤷 as mentioned before maybe I'm missing something here. Could you maybe take a look so that we may correct the issues there or my misunderstanding 🙈? I would be grateful 👍dd16390 |
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.
Thanks for the update, the path looks good to me.
Here are some comments to go to the next step.
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/PassConfig.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes_80.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...ony/Component/DependencyInjection/Tests/Compiler/ResolveAutowireInlineAttributesPassTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Compiler/ResolveAutowireInlineAttributesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Compiler/ResolveAutowireInlineAttributesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Compiler/ResolveAutowireInlineAttributesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Attribute/AutowireInline.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
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/ResolveAutowireInlineAttributesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| * @author Ismail Özgün Turan <oezguen.turan@dadadev.com> | ||
| */ | ||
| #[\Attribute(\Attribute::TARGET_PARAMETER)] | ||
| class AutowireInlineextends Autowire |
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.
AutowireInline looks pretty cryptic, any newcomer wouldn't be able to get what the attribute is for by just looking at its name nor its description as it currently is. I think we either need to find a super self-explanatory name (I've no clue) or extend the description so that it tells what's the purpose of the attribute and when it should be used (inline service definition only means something to advanced Symfony's DIC hackers)
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.
Naming things... :)
"inline" refers to "inline_service()" in the PHP-DSL
AutowireInlineService? but verbose
AutowireNew? AutowireObject? AutowireInstance? or keep AutowireInline?
of course, a top notch description is also desirable
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.
I added a better descriptionhere feel free to request further suggestments to it 👍.
0ad67af to5144ceaCompare964fe78 to19b1076Compare
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.
PR is ready.
I added a second commit to make the implementation a bit more generic.
Reviews welcome 🙏
| if (isset($this->definitions[$id])) { | ||
| unset($this->definitions[$id]); | ||
| $this->removedIds[$id] =true; | ||
| if ('.' !== ($id[0] ??'-')) { |
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.
I added this rule so that we don't use internal service ids in error messages. This matters to this PR because the added code creates new removed-ids, which means fixtures have to be updated with (what I consider as) noise.
…ice definition at the class level
19b1076 tob9a838eComparefabpot commentedMay 2, 2024
Thank you@DaDeather. |
Uh oh!
There was an error while loading.Please reload this page.
For the idea behind this feature see the issue that contains examples#52819
Example usage: