Преглед изворни кода

[Routing] removed call to setDefaultAnnotationNamespace() so this can be configure on the injected reader

Kris Wallsmith пре 14 година
родитељ
комит
32aef96441
1 измењених фајлова са 14 додато и 6 уклоњено
  1. 14 6
      src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

+ 14 - 6
src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

@@ -56,6 +56,7 @@ use Symfony\Component\Routing\Loader\LoaderResolver;
 abstract class AnnotationClassLoader implements LoaderInterface
 {
     protected $reader;
+    protected $annotationClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
 
     /**
      * Constructor.
@@ -67,6 +68,16 @@ abstract class AnnotationClassLoader implements LoaderInterface
         $this->reader = $reader;
     }
 
+    /**
+     * Sets the annotation class to read route properties from.
+     *
+     * @param string $annotationClass A fully-qualified class name
+     */
+    public function setAnnotationClass($annotationClass)
+    {
+        $this->annotationClass = $annotationClass;
+    }
+
     /**
      * Loads from annotations from a class.
      *
@@ -83,9 +94,6 @@ abstract class AnnotationClassLoader implements LoaderInterface
             throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
         }
 
-        $class = new \ReflectionClass($class);
-        $annotClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
-
         $globals = array(
             'pattern'      => '',
             'requirements' => array(),
@@ -93,7 +101,8 @@ abstract class AnnotationClassLoader implements LoaderInterface
             'defaults'     => array(),
         );
 
-        if ($annot = $this->reader->getClassAnnotation($class, $annotClass)) {
+        $class = new \ReflectionClass($class);
+        if ($annot = $this->reader->getClassAnnotation($class, $this->annotationClass)) {
             if (null !== $annot->getPattern()) {
                 $globals['pattern'] = $annot->getPattern();
             }
@@ -111,10 +120,9 @@ abstract class AnnotationClassLoader implements LoaderInterface
             }
         }
 
-        $this->reader->setDefaultAnnotationNamespace('Symfony\\Component\\Routing\\Annotation\\');
         $collection = new RouteCollection();
         foreach ($class->getMethods() as $method) {
-            if ($annot = $this->reader->getMethodAnnotation($method, $annotClass)) {
+            if ($annot = $this->reader->getMethodAnnotation($method, $this->annotationClass)) {
                 if (null === $annot->getName()) {
                     $annot->setName($this->getDefaultRouteName($class, $method));
                 }