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:

  1. The class is already defined. That is, class_exists($class, FALSE) returns TRUE.
  2. The class is in an annotation namespaces registered with the parser, and can be loaded with Doctrine's PSR-0 style annotation class loader.
  3. 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:

  1. Some annotation classes can be unreachable for the regular class loader. But still that is stupid.
  2. 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.

Comments

donquixote’s picture

The 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

donquixote’s picture

Note:
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.

donquixote’s picture

Status: Active » Needs review
StatusFileSize
new1.51 KB

Let's see what happens!

eclipsegc’s picture

Status: Needs review » Active

Maybe I should have posted it here, but my attempt at solving this: #2084513: Annotation class loading could be more elegant.

Eclipse

eclipsegc’s picture

Status: Active » Closed (fixed)

I think we can close this? since #2084513: Annotation class loading could be more elegant. got in?

Eclipse

donquixote’s picture

Yes. Strictly speaking, the other one was the dupe.. but I don't care :)