Skip to content

Commit d0bbc35

Browse files
committed
Bug fixed about URI parameters for Groups.
1 parent 9d9ce5a commit d0bbc35

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Router.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,20 @@ public function run(): void
298298
$route = str_replace($searches, $replaces, $route);
299299
if (preg_match('#^' . $route . '$#', $uri, $matched)) {
300300
$foundRoute = true;
301+
301302
$this->runRouteMiddleware($data, 'before');
303+
302304
array_shift($matched);
303305
$matched = array_map(function ($value) {
304306
return trim(urldecode($value));
305307
}, $matched);
308+
309+
foreach ($data['groups'] as $group) {
310+
if (strstr($group, ':') !== false) {
311+
array_shift($matched);
312+
}
313+
}
314+
306315
$this->runRouteCommand($data['callback'], $matched);
307316
$this->runRouteMiddleware($data, 'after');
308317
break;
@@ -692,11 +701,13 @@ protected function loadCache(): bool
692701
protected function addRoute(string $uri, string $method, $callback, $options = [])
693702
{
694703
$groupUri = '';
704+
$groupStack = [];
695705
$beforeMiddlewares = [];
696706
$afterMiddlewares = [];
697707
if (!empty($this->groups)) {
698708
foreach ($this->groups as $key => $value) {
699709
$groupUri .= $value['route'];
710+
$groupStack[] = trim($value['route'], '/');
700711
$beforeMiddlewares = array_merge($beforeMiddlewares, $value['before']);
701712
$afterMiddlewares = array_merge($afterMiddlewares, $value['after']);
702713
}
@@ -718,6 +729,7 @@ protected function addRoute(string $uri, string $method, $callback, $options = [
718729
'name' => $options['name'] ?? $routeName,
719730
'before' => $beforeMiddlewares,
720731
'after' => $afterMiddlewares,
732+
'groups' => $groupStack,
721733
];
722734
array_unshift($this->routes, $data);
723735
}

0 commit comments

Comments
 (0)