Adding class/interface tagging #42499
Replies: 5 comments 4 replies
-
I miss as well automatic tagging of services on the interface they implement |
Beta Was this translation helpful? Give feedback.
-
Based on the number of upvotes it seems I am not the only one who would like to see this become availble. I will start working on a PR to offer this functionality to the Laravel framework. |
Beta Was this translation helpful? Give feedback.
-
I have opened a pull request and awaiting approval. #44164 |
Beta Was this translation helpful? Give feedback.
-
Anything on this? We need this badly |
Beta Was this translation helpful? Give feedback.
-
Been trying Laravel for fun and was disappointed to see that such a useful feature is not built-in 😮 |
Beta Was this translation helpful? Give feedback.
-
Idea
I would love to have a feature in Laravel that enables us as developers to auto tag all the classes that implement an interface or extend a certain class.
The behaviour of this would be comparable with autoconfiguring tags from Symfony.
Inner workings
For a project a made a PoC (Proof of Concept) for this where I used the classmapper from Composer to scan all the classes within a namespace (the namespace could be provided through a configuration). If the class extends / implements the expected class/interface, its service would receive the provided tag.
In the code the user could do something like the following in their service provider / app:
The performance penalty of doing this on runtime seemed to be marginal (less then 0.1 sec on a large application (+1700 classes), but I would recommend to make in the PoC I introduced a caching mechanism which prevented rerunning the same code when nothing changed.
Why would I use this
The use case for me was that I was implementing a service which retrieved a couple of handlers following the strategy pattern. This functionality enabled me to quickly add and remove handlers without having to manually declare them in a service provider or config.
Beta Was this translation helpful? Give feedback.
All reactions