summaryrefslogtreecommitdiff
path: root/src/Router.php
diff options
context:
space:
mode:
authorSam Light <sam@lightscale.co.uk>2026-06-10 19:00:33 +0100
committerSam Light <sam@lightscale.co.uk>2026-06-10 19:00:33 +0100
commiteb9aa22170ce921d2816db539dd865986f0ba6bc (patch)
tree89495041a4da27e7b4536b058a9a6dc041fdf843 /src/Router.php
parentfe39ea0aa5a6993ad5edaa6f0f338763ed610ec9 (diff)
testing middleware dispatch
Diffstat (limited to 'src/Router.php')
-rw-r--r--src/Router.php27
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,
+ ))
+ )
);
}