Compare commits

...

2 Commits

Author SHA1 Message Date
8df2e64872
Merge pull request 'unify url handling for routes and redirect' (#5) from feature/unify-url-handling into master
All checks were successful
soko-web/pipeline/head This commit looks good
Reviewed-on: #5
2023-04-16 20:45:23 +02:00
427426bebe
unify url handling for routes and redirect
All checks were successful
soko-web/pipeline/pr-master This commit looks good
2023-04-16 20:33:22 +02:00
3 changed files with 6 additions and 5 deletions

View File

@ -19,7 +19,7 @@ class Redirect implements IRedirect
if (preg_match('/^http(s)?/', $this->target) === 1) { if (preg_match('/^http(s)?/', $this->target) === 1) {
$link = $this->target; $link = $this->target;
} else { } else {
$link = \Container::$request->getBase() . '/' . $this->target; $link = \Container::$request->getBase() . $this->target;
} }
return $link; return $link;

View File

@ -53,7 +53,7 @@ class Route
$query = count($queryParams) > 0 ? '?' . http_build_query($queryParams) : ''; $query = count($queryParams) > 0 ? '?' . http_build_query($queryParams) : '';
return implode('/', $link) . $query; return '/' . implode('/', $link) . $query;
} }
public function testAgainst(array $path): ?array public function testAgainst(array $path): ?array

View File

@ -41,9 +41,10 @@ class RouteCollection
return $this->routes[$id]; 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 // response to HEAD request with the GET content
if ($method === 'head') { if ($method === 'head') {
@ -55,7 +56,7 @@ class RouteCollection
} }
foreach ($this->searchTable[$method][$groupNumber] as $route) { foreach ($this->searchTable[$method][$groupNumber] as $route) {
if (($parameters = $route->testAgainst($uri)) !== null) { if (($parameters = $route->testAgainst($path)) !== null) {
return [$route, $parameters]; return [$route, $parameters];
} }
} }