diff options
| author | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:33 +0100 |
|---|---|---|
| committer | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:33 +0100 |
| commit | fe39ea0aa5a6993ad5edaa6f0f338763ed610ec9 (patch) | |
| tree | a466975d5194c89dd817437654fb5c3c84b7699d /src | |
| parent | 1a9da09ccc68c7a8fdc8a1d9989e8916ac442f9e (diff) | |
Make it so the router will call the middleware
Diffstat (limited to 'src')
| -rw-r--r-- | src/Router.php | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Router.php b/src/Router.php index 46eadd8..d70b278 100644 --- a/src/Router.php +++ b/src/Router.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Lightscale\Router; +use Lightscale\Router\Contracts\Middleware; use Lightscale\Router\Contracts\Strategy; use Lightscale\Router\Enums\HttpMethod; use Lightscale\Router\Enums\PathSegmentType; @@ -117,17 +118,29 @@ class Router ); } + /** @return Middleware[] */ + private function getRouteMiddleware(Route $route): array + { + return [ + ...$this->getMiddleware(), + ...($route->getGroup() ?? []), + ...$route->getMiddleware(), + ]; + return []; + } + public function dispatch(RequestInterface $request): ResponseInterface { $uri = $request->getUri(); $match = $this->findRoute($request->getMethod(), $uri->getPath()); + if (null === $match) { return $this->strategy->notFound($request); } return $this->strategy->runMiddleware( $request, - [], + $this->getRouteMiddleware($match->route), fn ($request) => $this->strategy->runRoute(new RouteCall( $request, $match->route, |
