Le 01/07/2011 10:23, Benjamin Eberlei a écrit :
On Fri, 01 Jul 2011 10:17:17 +0200, Christophe COEVOET wrote:
Le 01/07/2011 10:12, Benjamin Eberlei a écrit :
Yes, I know this is a problem, but even in the case currently all the annotation classes have to be made available (through an autoloader). Registering all possible annotations either with their class name in a hashmap or already calling require_once on them is just another mechanism that is not as convenient but allows more robust docblock parsing. Also the "hack" to doctrine annotations loading is only necessary, because these classes are organized in a non psr-0 structure. So these classes are pre-loaded in a hackish way, because there is no other mechanism for the autoload = true case.

We already set annotations: true for validators and registering the ExtraBundles is also a statement "pro annotation", so we do have simple ways in Symfony2 to collect the class-names of all possible annotations. I propose to change the following on AnnotationReader:

1. Add a method to register annotation classes: $reader->registerAnnotation("Symfony\Bridge\Doctrine\Validator\UniqueEntity"); and $reader->registerAnnotations(array(..)); 2. Add a method to register files that contain annotations: $reader->registerAnnotationFile(".."), directly loading them via require_once; 3. Add a method to register annotation namespaces: $reader->registerAnnotationNamespace("Symfony\Component\Validator\Constraint", $dir). This is used to create a silently failing PSR-0 "autoloader" for this path + directories. It can be automatically populated from data in the UniversalClassLoader. 4. Change the class_exists check to never use autoload = true. If a class is part of a registered annotation namespace (only directly in the exact namespace, no subnamspacing), try load the file based on a silent PSR-0 autoload for it using an autoloader impl. contained in the AnnotationReader (not the php autoloading mechanism), before triggering the class_exists($name, false)

This way for symfony only the UniversalClassLoader data has to be used to populate the registered annotation namespaces.
This seems good. And in Symfony, we can implement it by adding a tag
on services in which the annotation reader is injected giving the
needed data to register the annotations in the annotation_reader
service. This will require a bit work for people writing an annotation
driver but they still have to work.
This should probably be done before the Symfony2 release to avoid BC
issues after that.

A tag is not necessary, the data from the universal class loader would suffice to register the new autoloader inside the annotation reader. Doctrine Bundle (and third party ones in need of special integration) could use a compiler pass to add the $reader->registerAnnotationFile() call. This would cover 99,9% of all use-cases.

But registering which namespaces ? You would register all namespaces of the autoloader instead of just the one containing annotations ?

--
Christophe | Stof

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to