-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Allow attribute autoconfiguration on static methods #47066
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
Conversation
Can you please give a more concrete use case? I don't understand the point for now. This would need test cases of course before being accepted. |
Use cases
TestsI have not seen any tests for complex attributes in the compiler pass unit test. If you can point me at some classes that may have relevant tests, I'd be happy to test my changes. |
The concept of "static" and "service" look orthogonal to me. Static is a kind of global state while a service is an instance, aka it has a local scope only. For methods, if they're purely functional, why not, but for properties, what's the use case? |
I just removed checks for properties because it seemed purely arbitrary to support static methods and not static properties. Currently I'm implementing a workflow abstraction based on attributes. Configuring a single workflow is through a static method. Transition guards/actions are mere callable so anything that can be registered in the container (static or instance) can be used. Sure, everything could be forced to be instance methods, but the overhead of instantiating a service on something that can be a simple closure is kinda annoying. |
So, you are using a static method as a factory for a closure and you're adding attributes on that factory to configure how it is wired? Works for me. But that's no-go for properties. There is nothing arbitrary there: a static property is global state. These don't belong to service configuration. |
That's fine for me. I will fix the PR, just let me know where I could find relevant tests so I can add to them. |
There is only src/Symfony/Component/DependencyInjection/Tests/Compiler/AttributeAutoconfigurationPassTest.php :) |
Friendly ping @alex-dev |
Ok.... Work is always hectic around Christmas. I could secure time for Symfony work in the next few weeks... I plan to finish this PR, and work on a few other issues I've reported, will report or have already been reported that have been annoying my coworkers... Should see a bit more of me in the next few weeks. |
c7a7d2e
to
89d9363
Compare
838df90
to
9908415
Compare
Thank you @alex-dev. |
With #101596 event listener registrations were migrated to PHP attributes. Service registrations may only be performed on non-static methods with symfony/dependency-injection <6.3 [1]. This caused the 'non-composer-class-loader' events to be silently skipped, which is why no class loading information was dumped. ClassLoadingInformation event listeners are moved into a separate service with an instance method to circumvent this bug in symfony/dependency-injection. Also stray and unneeded Services.yaml configuration is removed. (public: false is the default and does not need to be set at all) [1] symfony/symfony#47066 Resolves: #101679 Resolves: #101681 Related: #101596 Releases: main Change-Id: Ie18b8f1123364073a5df7a07b6f8bf71d27cd150 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80546 Reviewed-by: Stefan B�rk <[email protected]> Tested-by: core-ci <[email protected]> Tested-by: Stefan B�rk <[email protected]> Reviewed-by: Benjamin Franzke <[email protected]> Tested-by: Benjamin Franzke <[email protected]>
With #101596 event listener registrations were migrated to PHP attributes. Service registrations may only be performed on non-static methods with symfony/dependency-injection <6.3 [1]. This caused the 'non-composer-class-loader' events to be silently skipped, which is why no class loading information was dumped. ClassLoadingInformation event listeners are moved into a separate service with an instance method to circumvent this bug in symfony/dependency-injection. Also stray and unneeded Services.yaml configuration is removed. (public: false is the default and does not need to be set at all) [1] symfony/symfony#47066 Resolves: #101679 Resolves: #101681 Related: #101596 Releases: main Change-Id: Ie18b8f1123364073a5df7a07b6f8bf71d27cd150 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80546 Reviewed-by: Stefan B�rk <[email protected]> Tested-by: core-ci <[email protected]> Tested-by: Stefan B�rk <[email protected]> Reviewed-by: Benjamin Franzke <[email protected]> Tested-by: Benjamin Franzke <[email protected]>
A static method can be used to carry complex configuration payload for DI.
A static method can be used to generate a Closure that can be hooked in the container (a static message handler with no dependency).
Using simple attribute autoconfigurator to wire those case easily.