Helper issue for #2033611: Port AnnotatedClassDiscovery to PSR-4, and make it agnostic of directory information.
Our AnnotatedClassDiscovery uses some Doctrine code to parse annotations on classes.
Whenever the parser hits an annotation, it will check whether that's a known annotation class name.
An annotation class is "known" if one of the following is true:
- The class is already defined. That is, class_exists($class, FALSE) returns TRUE.
- The class is in an annotation namespaces registered with the parser, and can be loaded with Doctrine's PSR-0 style annotation class loader.
- The class can be loaded with a registered custom class loader.
It does NOT, however, trigger the regular class loader on the SPL autoload stack.
This system has a side effect that makes it dead stupid:
If we run discovery D1 which loads annotation class C1, and then we run discovery D2, then on D2 the annotation class C1 will be considered "known" even if that is not intended for D2.
I could see two valid use cases:
- Some annotation classes can be unreachable for the regular class loader. But still that is stupid.
- A class is reachable by the regular class loader, but we don't want it to be loaded, because loading the class may have side effects.
In our case, all annotation classes are already reachable with the regular class loader, and we don't have to be afraid of any of them to be included. So all the annotation namespaces stuff is bogus. We can as well just use the regular class loader and be done with it.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | D8-custom-annotation-class-loader-2083335-3.patch | 1.51 KB | donquixote |
Comments
Comment #1
donquixote commentedThe other option would be to only manage a list of namespaces, but no associated directories.
Because we can use the regular class loader for that.
So, our custom annotation class loader would
- check if the class is within one of the namespaces
- check if the class can be loaded with the regular class loader
Comment #2
donquixote commentedNote:
We NEED to provide our own custom annotation class loader, because the one in Doctrine does only accept PSR-0 mappings, not PSR-4.
So the idea is to have a custom loader, with a shortcut that allows us to avoid dealing with directories.
#2033611-36: Port AnnotatedClassDiscovery to PSR-4, and make it agnostic of directory information. already has a custom loader, but still goes a long way in dealing with directories.
Comment #3
donquixote commentedLet's see what happens!
Comment #4
eclipsegc commentedMaybe I should have posted it here, but my attempt at solving this: #2084513: Annotation class loading could be more elegant.
Eclipse
Comment #5
eclipsegc commentedI think we can close this? since #2084513: Annotation class loading could be more elegant. got in?
Eclipse
Comment #6
donquixote commentedYes. Strictly speaking, the other one was the dupe.. but I don't care :)