unify url handling for routes and redirect
All checks were successful
soko-web/pipeline/pr-master This commit looks good
All checks were successful
soko-web/pipeline/pr-master This commit looks good
This commit is contained in:
parent
014a548096
commit
427426bebe
@ -19,7 +19,7 @@ class Redirect implements IRedirect
|
||||
if (preg_match('/^http(s)?/', $this->target) === 1) {
|
||||
$link = $this->target;
|
||||
} else {
|
||||
$link = \Container::$request->getBase() . '/' . $this->target;
|
||||
$link = \Container::$request->getBase() . $this->target;
|
||||
}
|
||||
|
||||
return $link;
|
||||
|
@ -53,7 +53,7 @@ class Route
|
||||
|
||||
$query = count($queryParams) > 0 ? '?' . http_build_query($queryParams) : '';
|
||||
|
||||
return implode('/', $link) . $query;
|
||||
return '/' . implode('/', $link) . $query;
|
||||
}
|
||||
|
||||
public function testAgainst(array $path): ?array
|
||||
|
@ -41,9 +41,10 @@ class RouteCollection
|
||||
return $this->routes[$id];
|
||||
}
|
||||
|
||||
public function match(string $method, array $uri): ?array
|
||||
public function match(string $method, string $uri): ?array
|
||||
{
|
||||
$groupNumber = count($uri);
|
||||
$path = $uri === '/' ? [] : explode('/', ltrim($uri, '/'));
|
||||
$groupNumber = count($path);
|
||||
|
||||
// response to HEAD request with the GET content
|
||||
if ($method === 'head') {
|
||||
@ -55,7 +56,7 @@ class RouteCollection
|
||||
}
|
||||
|
||||
foreach ($this->searchTable[$method][$groupNumber] as $route) {
|
||||
if (($parameters = $route->testAgainst($uri)) !== null) {
|
||||
if (($parameters = $route->testAgainst($path)) !== null) {
|
||||
return [$route, $parameters];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user