summaryrefslogtreecommitdiff
path: root/src/Route.php
blob: f432d612ddb39bb6d75c41dd25756a57124dfb9c (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
42
43
44
45
46
47
48
49
50
51
52
53
<?php

declare(strict_types=1);

namespace Lightscale\Router;

use Closure;
use Lightscale\Router\Enums\HttpMethod;

class Route
{
    protected Closure $handler;

    protected PathSegment $segment;

    public function __construct(
        protected HttpMethod $method,
        callable $handler,
        ?PathSegment $segment = null,
    ) {
        $this->handler = Closure::fromCallable($handler);

        if (null !== $segment) {
            $this->segment = $segment;
        }
    }

    public function getMethod(): HttpMethod
    {
        return $this->method;
    }

    public function setSegment(PathSegment $segment): void
    {
        $this->segment = $segment;
    }

    public function getSegment(): PathSegment
    {
        return $this->segment;
    }

    /** @param array<string, string> $parameters */
    public function getPath(array $parameters = []): string
    {
        return $this->segment->getPath($parameters);
    }

    public function getHandler(): Closure
    {
        return $this->handler;
    }
}