Skip to content

Commit 32aef96

Browse files
kriswallsmithfabpot
authored andcommitted
[Routing] removed call to setDefaultAnnotationNamespace() so this can be configure on the injected reader
1 parent 8a472b7 commit 32aef96

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
abstract class AnnotationClassLoader implements LoaderInterface
5757
{
5858
protected $reader;
59+
protected $annotationClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
5960

6061
/**
6162
* Constructor.
@@ -67,6 +68,16 @@ public function __construct(AnnotationReader $reader)
6768
$this->reader = $reader;
6869
}
6970

71+
/**
72+
* Sets the annotation class to read route properties from.
73+
*
74+
* @param string $annotationClass A fully-qualified class name
75+
*/
76+
public function setAnnotationClass($annotationClass)
77+
{
78+
$this->annotationClass = $annotationClass;
79+
}
80+
7081
/**
7182
* Loads from annotations from a class.
7283
*
@@ -83,17 +94,15 @@ public function load($class, $type = null)
8394
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
8495
}
8596

86-
$class = new \ReflectionClass($class);
87-
$annotClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
88-
8997
$globals = array(
9098
'pattern' => '',
9199
'requirements' => array(),
92100
'options' => array(),
93101
'defaults' => array(),
94102
);
95103

96-
if ($annot = $this->reader->getClassAnnotation($class, $annotClass)) {
104+
$class = new \ReflectionClass($class);
105+
if ($annot = $this->reader->getClassAnnotation($class, $this->annotationClass)) {
97106
if (null !== $annot->getPattern()) {
98107
$globals['pattern'] = $annot->getPattern();
99108
}
@@ -111,10 +120,9 @@ public function load($class, $type = null)
111120
}
112121
}
113122

114-
$this->reader->setDefaultAnnotationNamespace('Symfony\\Component\\Routing\\Annotation\\');
115123
$collection = new RouteCollection();
116124
foreach ($class->getMethods() as $method) {
117-
if ($annot = $this->reader->getMethodAnnotation($method, $annotClass)) {
125+
if ($annot = $this->reader->getMethodAnnotation($method, $this->annotationClass)) {
118126
if (null === $annot->getName()) {
119127
$annot->setName($this->getDefaultRouteName($class, $method));
120128
}

0 commit comments

Comments
 (0)