diff options
Diffstat (limited to 'src/Router.php')
| -rw-r--r-- | src/Router.php | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/Router.php b/src/Router.php index d70b278..fcfc771 100644 --- a/src/Router.php +++ b/src/Router.php @@ -119,14 +119,13 @@ class Router } /** @return Middleware[] */ - private function getRouteMiddleware(Route $route): array + private function getRouteMiddleware(?Route $route): array { return [ ...$this->getMiddleware(), - ...($route->getGroup() ?? []), - ...$route->getMiddleware(), + ...($route?->getGroup()?->getMiddleware() ?? []), + ...($route?->getMiddleware() ?? []), ]; - return []; } public function dispatch(RequestInterface $request): ResponseInterface @@ -134,18 +133,18 @@ class Router $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, - $match->segmentMatch->parameters, - )) + $this->getRouteMiddleware($match?->route), + fn ($request) => ( + null === $match ? + $this->strategy->notFound($request) : + $this->strategy->runRoute(new RouteCall( + $request, + $match->route, + $match->segmentMatch->parameters, + )) + ) ); } |
