diff options
| author | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
|---|---|---|
| committer | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
| commit | 968662ee16a1efc7cb7c176a42af91f36eecc9ca (patch) | |
| tree | b700510f895c8e059f17d8fcabbb8b8d5471824f /src | |
| parent | 25780fef281782ce7e88c27cb23cb3d9e9d6bd03 (diff) | |
Create a group route and name it
Diffstat (limited to 'src')
| -rw-r--r-- | src/GroupDefinition.php | 6 | ||||
| -rw-r--r-- | src/RouteDefinition.php | 11 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/GroupDefinition.php b/src/GroupDefinition.php index 41e359d..1ffddc7 100644 --- a/src/GroupDefinition.php +++ b/src/GroupDefinition.php @@ -18,7 +18,11 @@ class GroupDefinition public function make(HttpMethod $method, string $path, callable $handler): RouteDefinition { - + return $this->group->getRouter()->make( + $method, + $this->group->getFullPrefix() . '/'. ltrim($path, '/'), + $handler + )->inGroup($this->group); } private function getGroup(): Group diff --git a/src/RouteDefinition.php b/src/RouteDefinition.php index fb10380..1ca9201 100644 --- a/src/RouteDefinition.php +++ b/src/RouteDefinition.php @@ -9,11 +9,22 @@ class RouteDefinition public function __construct( private Router $router, private Route $route, + private ?Group $group = null, ) { } + public function inGroup(Group $group): static + { + $this->group = $group; + return $this; + } + public function name(string $value): static { + if (($groupName = $this->group?->getFullName()) !== null) { + $value = $groupName . $value; + } + $this->router->addNamedRoute($value, $this->route); return $this; |
