From 32aef9644134f375f67e5685c4ffd48ea40536e3 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Mon, 20 Dec 2010 16:50:16 -0800 Subject: [PATCH] [Routing] removed call to setDefaultAnnotationNamespace() so this can be configure on the injected reader --- .../Routing/Loader/AnnotationClassLoader.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 0489409af090..3b24cefb9891 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -56,6 +56,7 @@ abstract class AnnotationClassLoader implements LoaderInterface { protected $reader; + protected $annotationClass = 'Symfony\\Component\\Routing\\Annotation\\Route'; /** * Constructor. @@ -67,6 +68,16 @@ public function __construct(AnnotationReader $reader) $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 @@ public function load($class, $type = null) 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 @@ public function load($class, $type = null) '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 @@ public function load($class, $type = null) } } - $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)); }