Skip to content

Commit

Permalink
RouteList: match() split into prepareRequest() and completeParameters()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 8, 2023
1 parent 0bf7d6e commit 1e90961
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/Routing/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}


Expand Down

0 comments on commit 1e90961

Please sign in to comment.