Problem/Motivation
Wondering if you could auto-discover classes in a compiler pass by looking for annotations, and hence avoid needing to declare a service.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork hux-3266008
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dpiIf not added as a service..
What did you have in mind in particular?
There is of course already a compiler pass which looks for tagged services,
Comment #4
dpiI've got some code I'm fiddling with, instead of a class attributes I'm just checking methods for any Hux attributes. Then creating a service for each class with the same tags as to-date functionality.
What do you think of this?
How do you think dep injection or otherwise should work?
Comment #5
larowlanLooks good, dependency injection could use ContainerInjectionInterface (ie controller resolver)
I wonder if you should check if there's already a definition in the container for the class, just in case someone has manually registered it.
Comment #6
dpiWith this approach it adds all the classes detected as a service. Which means that when I
->container->getthe service the class is created for me. I dont have the ability like ClassResolver to just call::create.Just had a thought about abusing factories to do this for me...
Comment #7
dpi@larowlan how does this look?
Comment #8
dpiadded! It will only ignore if same class and also tagged with “hooks”
Comment #9
larowlanAs mentioned in a call earlier in the week, this looks great - nice work!
Comment #11
dpiMerged!
Can be found in 1.0.0-beta4