diff options
| -rw-r--r-- | src/Concerns/CreatesGroups.php | 15 | ||||
| -rw-r--r-- | tests/Unit/RouterTest.php | 2 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/Concerns/CreatesGroups.php b/src/Concerns/CreatesGroups.php index 4a2b862..ae178a0 100644 --- a/src/Concerns/CreatesGroups.php +++ b/src/Concerns/CreatesGroups.php @@ -6,6 +6,7 @@ namespace Lightscale\Router\Concerns; use Lightscale\Router\Contracts\Middleware; use Lightscale\Router\Group; +use Lightscale\Router\GroupDefinition; trait CreatesGroups { @@ -38,4 +39,18 @@ trait CreatesGroups middleware: $value, ); } + + /** @param callable(GroupDefinition): void $cb */ + public function group(callable $cb): Group + { + $group = new Group( + router: $this->getRouter(), + parent: $this->getGroup(), + ); + ($cb)(new GroupDefinition( + $group + )); + + return $group; + } } diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php index bba7301..06cf8ff 100644 --- a/tests/Unit/RouterTest.php +++ b/tests/Unit/RouterTest.php @@ -464,7 +464,7 @@ describe('middleware', function () { $res6 = $this->factory->createResponse(); $this->router->middleware($mw3)->group(function ($group) use ( - $mw4, $res1, $res2, $res3, $res4, $mw5, $mw6 + $mw4, $res1, $res2, $res3, $res4, $mw5, $mw6 ) { $group->get('/test1', fn () => $res1); $group->get('/test2', fn () => $res2)->middleware($mw4); |
