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 | 5fe7c87967ff29c4a8f03a9186918d8359f4887e (patch) | |
| tree | dfdd4fdc7a4e96266305f82f5846750ab2efabc9 /src/Route.php | |
| parent | 01eac9658c3bc486d2d42a18557fdb82a536348e (diff) | |
big update
Diffstat (limited to 'src/Route.php')
| -rw-r--r-- | src/Route.php | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/Route.php b/src/Route.php index 1a9ad03..aeb3f66 100644 --- a/src/Route.php +++ b/src/Route.php @@ -6,16 +6,48 @@ namespace Lightscale\Router; use Closure; use Lightscale\Router\Enums\HttpMethod; +use Psr\Http\Message\RequestInterface; class Route { protected Closure $handler; + protected PathSegment $segment; + public function __construct( - protected PathSegment $segment, protected HttpMethod $method, callable $handler, + ?PathSegment $segment = null, ) { $this->handler = Closure::fromCallable($handler); + + if (null !== $segment) { + $this->segment = $segment; + } + } + + public function __invoke(RequestInterface $request): mixed + { + return ($this->handler)($request); + } + + public function getMethod(): HttpMethod + { + return $this->method; + } + + public function setSegment(PathSegment $segment): void + { + $this->segment = $segment; + } + + public function getSegment(): PathSegment + { + return $this->segment; + } + + public function getPath(): string + { + return $this->segment->getPath(); } } |
