@@ -298,11 +298,20 @@ public function run(): void
298
298
$ route = str_replace ($ searches , $ replaces , $ route );
299
299
if (preg_match ('#^ ' . $ route . '$# ' , $ uri , $ matched )) {
300
300
$ foundRoute = true ;
301
+
301
302
$ this ->runRouteMiddleware ($ data , 'before ' );
303
+
302
304
array_shift ($ matched );
303
305
$ matched = array_map (function ($ value ) {
304
306
return trim (urldecode ($ value ));
305
307
}, $ matched );
308
+
309
+ foreach ($ data ['groups ' ] as $ group ) {
310
+ if (strstr ($ group , ': ' ) !== false ) {
311
+ array_shift ($ matched );
312
+ }
313
+ }
314
+
306
315
$ this ->runRouteCommand ($ data ['callback ' ], $ matched );
307
316
$ this ->runRouteMiddleware ($ data , 'after ' );
308
317
break ;
@@ -692,11 +701,13 @@ protected function loadCache(): bool
692
701
protected function addRoute (string $ uri , string $ method , $ callback , $ options = [])
693
702
{
694
703
$ groupUri = '' ;
704
+ $ groupStack = [];
695
705
$ beforeMiddlewares = [];
696
706
$ afterMiddlewares = [];
697
707
if (!empty ($ this ->groups )) {
698
708
foreach ($ this ->groups as $ key => $ value ) {
699
709
$ groupUri .= $ value ['route ' ];
710
+ $ groupStack [] = trim ($ value ['route ' ], '/ ' );
700
711
$ beforeMiddlewares = array_merge ($ beforeMiddlewares , $ value ['before ' ]);
701
712
$ afterMiddlewares = array_merge ($ afterMiddlewares , $ value ['after ' ]);
702
713
}
@@ -718,6 +729,7 @@ protected function addRoute(string $uri, string $method, $callback, $options = [
718
729
'name ' => $ options ['name ' ] ?? $ routeName ,
719
730
'before ' => $ beforeMiddlewares ,
720
731
'after ' => $ afterMiddlewares ,
732
+ 'groups ' => $ groupStack ,
721
733
];
722
734
array_unshift ($ this ->routes , $ data );
723
735
}
0 commit comments