summaryrefslogtreecommitdiff
path: root/src/Concerns/CreatesGroups.php
blob: 4a2b862d7f69c5bea1a008ac7f1f224a00ced792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

declare(strict_types=1);

namespace Lightscale\Router\Concerns;

use Lightscale\Router\Contracts\Middleware;
use Lightscale\Router\Group;

trait CreatesGroups
{
    public function prefix(string $value): Group
    {
        return new Group(
            router: $this->getRouter(),
            parent: $this->getGroup(),
            prefix: $value,
        );
    }

    public function name(string $value): Group
    {
        return new Group(
            router: $this->getRouter(),
            parent: $this->getGroup(),
            name: $value,
        );
    }

    /** @param Middleware|Middleware[] $value */
    public function middleware(Middleware|array $value): Group
    {
        $value = is_array($value) ? $value : [$value];

        return new Group(
            router: $this->getRouter(),
            parent: $this->getGroup(),
            middleware: $value,
        );
    }
}