@@ -108,58 +108,12 @@ public function load($class, $type = null)
108
108
throw new \InvalidArgumentException (sprintf ('Class "%s" does not exist. ' , $ class ));
109
109
}
110
110
111
- $ globals = array (
112
- 'path ' => '' ,
113
- 'requirements ' => array (),
114
- 'options ' => array (),
115
- 'defaults ' => array (),
116
- 'schemes ' => array (),
117
- 'methods ' => array (),
118
- 'host ' => '' ,
119
- 'condition ' => '' ,
120
- );
121
-
122
111
$ class = new \ReflectionClass ($ class );
123
112
if ($ class ->isAbstract ()) {
124
113
throw new \InvalidArgumentException (sprintf ('Annotations from class "%s" cannot be read as it is abstract. ' , $ class ));
125
114
}
126
115
127
- if ($ annot = $ this ->reader ->getClassAnnotation ($ class , $ this ->routeAnnotationClass )) {
128
- // for BC reasons
129
- if (null !== $ annot ->getPath ()) {
130
- $ globals ['path ' ] = $ annot ->getPath ();
131
- } elseif (null !== $ annot ->getPattern ()) {
132
- $ globals ['path ' ] = $ annot ->getPattern ();
133
- }
134
-
135
- if (null !== $ annot ->getRequirements ()) {
136
- $ globals ['requirements ' ] = $ annot ->getRequirements ();
137
- }
138
-
139
- if (null !== $ annot ->getOptions ()) {
140
- $ globals ['options ' ] = $ annot ->getOptions ();
141
- }
142
-
143
- if (null !== $ annot ->getDefaults ()) {
144
- $ globals ['defaults ' ] = $ annot ->getDefaults ();
145
- }
146
-
147
- if (null !== $ annot ->getSchemes ()) {
148
- $ globals ['schemes ' ] = $ annot ->getSchemes ();
149
- }
150
-
151
- if (null !== $ annot ->getMethods ()) {
152
- $ globals ['methods ' ] = $ annot ->getMethods ();
153
- }
154
-
155
- if (null !== $ annot ->getHost ()) {
156
- $ globals ['host ' ] = $ annot ->getHost ();
157
- }
158
-
159
- if (null !== $ annot ->getCondition ()) {
160
- $ globals ['condition ' ] = $ annot ->getCondition ();
161
- }
162
- }
116
+ $ globals = $ this ->getGlobals ($ class );
163
117
164
118
$ collection = new RouteCollection ();
165
119
$ collection ->addResource (new FileResource ($ class ->getFileName ()));
@@ -252,5 +206,58 @@ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMetho
252
206
return $ name ;
253
207
}
254
208
209
+ protected function getGlobals (\ReflectionClass $ class )
210
+ {
211
+ $ globals = array (
212
+ 'path ' => '' ,
213
+ 'requirements ' => array (),
214
+ 'options ' => array (),
215
+ 'defaults ' => array (),
216
+ 'schemes ' => array (),
217
+ 'methods ' => array (),
218
+ 'host ' => '' ,
219
+ 'condition ' => '' ,
220
+ );
221
+
222
+ if ($ annot = $ this ->reader ->getClassAnnotation ($ class , $ this ->routeAnnotationClass )) {
223
+ // for BC reasons
224
+ if (null !== $ annot ->getPath ()) {
225
+ $ globals ['path ' ] = $ annot ->getPath ();
226
+ } elseif (null !== $ annot ->getPattern ()) {
227
+ $ globals ['path ' ] = $ annot ->getPattern ();
228
+ }
229
+
230
+ if (null !== $ annot ->getRequirements ()) {
231
+ $ globals ['requirements ' ] = $ annot ->getRequirements ();
232
+ }
233
+
234
+ if (null !== $ annot ->getOptions ()) {
235
+ $ globals ['options ' ] = $ annot ->getOptions ();
236
+ }
237
+
238
+ if (null !== $ annot ->getDefaults ()) {
239
+ $ globals ['defaults ' ] = $ annot ->getDefaults ();
240
+ }
241
+
242
+ if (null !== $ annot ->getSchemes ()) {
243
+ $ globals ['schemes ' ] = $ annot ->getSchemes ();
244
+ }
245
+
246
+ if (null !== $ annot ->getMethods ()) {
247
+ $ globals ['methods ' ] = $ annot ->getMethods ();
248
+ }
249
+
250
+ if (null !== $ annot ->getHost ()) {
251
+ $ globals ['host ' ] = $ annot ->getHost ();
252
+ }
253
+
254
+ if (null !== $ annot ->getCondition ()) {
255
+ $ globals ['condition ' ] = $ annot ->getCondition ();
256
+ }
257
+ }
258
+
259
+ return $ globals ;
260
+ }
261
+
255
262
abstract protected function configureRoute (Route $ route , \ReflectionClass $ class , \ReflectionMethod $ method , $ annot );
256
263
}
0 commit comments