56
56
abstract class AnnotationClassLoader implements LoaderInterface
57
57
{
58
58
protected $ reader ;
59
+ protected $ annotationClass = 'Symfony \\Component \\Routing \\Annotation \\Route ' ;
59
60
60
61
/**
61
62
* Constructor.
@@ -67,6 +68,16 @@ public function __construct(AnnotationReader $reader)
67
68
$ this ->reader = $ reader ;
68
69
}
69
70
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
+
70
81
/**
71
82
* Loads from annotations from a class.
72
83
*
@@ -83,17 +94,15 @@ public function load($class, $type = null)
83
94
throw new \InvalidArgumentException (sprintf ('Class "%s" does not exist. ' , $ class ));
84
95
}
85
96
86
- $ class = new \ReflectionClass ($ class );
87
- $ annotClass = 'Symfony \\Component \\Routing \\Annotation \\Route ' ;
88
-
89
97
$ globals = array (
90
98
'pattern ' => '' ,
91
99
'requirements ' => array (),
92
100
'options ' => array (),
93
101
'defaults ' => array (),
94
102
);
95
103
96
- if ($ annot = $ this ->reader ->getClassAnnotation ($ class , $ annotClass )) {
104
+ $ class = new \ReflectionClass ($ class );
105
+ if ($ annot = $ this ->reader ->getClassAnnotation ($ class , $ this ->annotationClass )) {
97
106
if (null !== $ annot ->getPattern ()) {
98
107
$ globals ['pattern ' ] = $ annot ->getPattern ();
99
108
}
@@ -111,10 +120,9 @@ public function load($class, $type = null)
111
120
}
112
121
}
113
122
114
- $ this ->reader ->setDefaultAnnotationNamespace ('Symfony \\Component \\Routing \\Annotation \\' );
115
123
$ collection = new RouteCollection ();
116
124
foreach ($ class ->getMethods () as $ method ) {
117
- if ($ annot = $ this ->reader ->getMethodAnnotation ($ method , $ annotClass )) {
125
+ if ($ annot = $ this ->reader ->getMethodAnnotation ($ method , $ this -> annotationClass )) {
118
126
if (null === $ annot ->getName ()) {
119
127
$ annot ->setName ($ this ->getDefaultRouteName ($ class , $ method ));
120
128
}
0 commit comments