From 1e90961f3d28ca4bf3e1d006e4eca2865576c392 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 5 Oct 2023 21:28:05 +0200 Subject: [PATCH] RouteList: match() split into prepareRequest() and completeParameters() --- src/Routing/RouteList.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Routing/RouteList.php b/src/Routing/RouteList.php index cbefe7d..f3a76e3 100644 --- a/src/Routing/RouteList.php +++ b/src/Routing/RouteList.php @@ -48,8 +48,25 @@ public function __construct() /** * Maps HTTP request to an array. + * @final */ public function match(Nette\Http\IRequest $httpRequest): ?array + { + if ($httpRequest = $this->prepareRequest($httpRequest)) { + foreach ($this->list as [$router]) { + if ( + ($params = $router->match($httpRequest)) !== null + && ($params = $this->completeParameters($params)) !== null + ) { + return $params; + } + } + } + return null; + } + + + protected function prepareRequest(Nette\Http\IRequest $httpRequest): ?Nette\Http\IRequest { if ($this->domain) { $host = $httpRequest->getUrl()->getHost(); @@ -68,14 +85,13 @@ public function match(Nette\Http\IRequest $httpRequest): ?array $httpRequest = $httpRequest->withUrl($url); } - foreach ($this->list as [$router]) { - $params = $router->match($httpRequest); - if ($params !== null) { - return $params; - } - } + return $httpRequest; + } - return null; + + protected function completeParameters(array $params): ?array + { + return $params; }