diff options
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(); } } |
