@@ -194,7 +194,7 @@ public function match(string $path, string $method = 'GET'): array
194
194
195
195
// is a regular dynamic route(the first node is 1th level index key).
196
196
if ($ first && isset ($ this ->regularRoutes [$ first ])) {
197
- $ result = $ this ->findInRegularRoutes ($ this -> regularRoutes [ $ first] , $ path , $ method );
197
+ $ result = $ this ->findInRegularRoutes ($ first , $ path , $ method );
198
198
199
199
if ($ result [0 ] === self ::FOUND ) {
200
200
return $ result ;
@@ -204,12 +204,8 @@ public function match(string $path, string $method = 'GET'): array
204
204
}
205
205
206
206
// is a irregular dynamic route
207
- if (isset ($ this ->vagueRoutes [$ method ])) {
208
- $ result = $ this ->findInVagueRoutes ($ this ->vagueRoutes [$ method ], $ path , $ method );
209
-
210
- if ($ result [0 ] === self ::FOUND ) {
211
- return $ result ;
212
- }
207
+ if ($ result = $ this ->findInVagueRoutes ($ path , $ method )) {
208
+ return $ result ;
213
209
}
214
210
215
211
// handle Auto Route
@@ -226,19 +222,15 @@ public function match(string $path, string $method = 'GET'): array
226
222
}
227
223
228
224
if ($ first && isset ($ this ->regularRoutes [$ first ])) {
229
- $ result = $ this ->findInRegularRoutes ($ this -> regularRoutes [ $ first] , $ path , 'GET ' );
225
+ $ result = $ this ->findInRegularRoutes ($ first , $ path , 'GET ' );
230
226
231
227
if ($ result [0 ] === self ::FOUND ) {
232
228
return $ result ;
233
229
}
234
230
}
235
231
236
- if (isset ($ this ->vagueRoutes ['GET ' ])) {
237
- $ result = $ this ->findInVagueRoutes ($ this ->vagueRoutes ['GET ' ], $ path , 'GET ' );
238
-
239
- if ($ result [0 ] === self ::FOUND ) {
240
- return $ result ;
241
- }
232
+ if ($ result = $ this ->findInVagueRoutes ($ path , 'GET ' )) {
233
+ return $ result ;
242
234
}
243
235
}
244
236
@@ -276,9 +268,7 @@ protected function findAllowedMethods(string $path, string $method, array $allow
276
268
continue ;
277
269
}
278
270
279
- $ result = $ this ->findInVagueRoutes ($ this ->vagueRoutes ['GET ' ], $ path , $ m );
280
-
281
- if ($ result [0 ] === self ::FOUND ) {
271
+ if ($ this ->findInVagueRoutes ($ path , $ m )) {
282
272
$ allowedMethods [] = $ method ;
283
273
}
284
274
}
@@ -292,16 +282,18 @@ protected function findAllowedMethods(string $path, string $method, array $allow
292
282
}
293
283
294
284
/**
295
- * @param array $routesData
285
+ * @param string $first
296
286
* @param string $path
297
287
* @param string $method
298
288
* @return array
299
289
*/
300
- protected function findInRegularRoutes (array $ routesData , string $ path , string $ method ): array
290
+ protected function findInRegularRoutes (string $ first , string $ path , string $ method ): array
301
291
{
302
292
$ allowedMethods = '' ;
293
+ /** @var array $routesInfo */
294
+ $ routesInfo = $ this ->regularRoutes [$ first ];
303
295
304
- foreach ($ routesData as $ conf ) {
296
+ foreach ($ routesInfo as $ conf ) {
305
297
if (0 === \strpos ($ path , $ conf ['start ' ]) && \preg_match ($ conf ['regex ' ], $ path , $ matches )) {
306
298
$ allowedMethods .= $ conf ['methods ' ];
307
299
@@ -320,14 +312,20 @@ protected function findInRegularRoutes(array $routesData, string $path, string $
320
312
}
321
313
322
314
/**
323
- * @param array $routesData
324
315
* @param string $path
325
316
* @param string $method
326
- * @return array
317
+ * @return array|false
327
318
*/
328
- protected function findInVagueRoutes (array $ routesData , string $ path , string $ method ): array
319
+ protected function findInVagueRoutes (string $ path , string $ method )
329
320
{
330
- foreach ($ routesData as $ conf ) {
321
+ if (!isset ($ this ->vagueRoutes [$ method ])) {
322
+ return false ;
323
+ }
324
+
325
+ /** @var array $routeList */
326
+ $ routeList = $ this ->vagueRoutes [$ method ];
327
+
328
+ foreach ($ routeList as $ conf ) {
331
329
if ($ conf ['start ' ] && 0 !== \strpos ($ path , $ conf ['start ' ])) {
332
330
continue ;
333
331
}
@@ -339,7 +337,7 @@ protected function findInVagueRoutes(array $routesData, string $path, string $me
339
337
}
340
338
}
341
339
342
- return [ self :: NOT_FOUND ] ;
340
+ return false ;
343
341
}
344
342
345
343
/*******************************************************************************
0 commit comments