summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Light <sam@lightscale.co.uk>2026-06-10 19:24:17 +0100
committerSam Light <sam@lightscale.co.uk>2026-06-10 19:24:17 +0100
commitd2a3da17cea4e172949ceac033e2455be0466b94 (patch)
tree5eecab89f973ccd867ce881db17558cf5bfb0482
parent13388b70c53952b6c1e637c38cb1b86d3b90c04e (diff)
creates group can directly create a group
-rw-r--r--src/Concerns/CreatesGroups.php15
-rw-r--r--tests/Unit/RouterTest.php2
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);