Utilise le chemin de base plus tard dans le routeur
This commit is contained in:
@@ -27,9 +27,6 @@ class Router
|
|||||||
|
|
||||||
public function setBasePath(string $basePath)
|
public function setBasePath(string $basePath)
|
||||||
{
|
{
|
||||||
if (PathHelper::startsWith($this->url, $basePath)) {
|
|
||||||
$this->url = trim(substr($this->url, strlen($basePath)), '/');
|
|
||||||
}
|
|
||||||
$this->basePath = $basePath;
|
$this->basePath = $basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +64,17 @@ class Router
|
|||||||
if (!isset($this->routes[$_SERVER['REQUEST_METHOD']])) {
|
if (!isset($this->routes[$_SERVER['REQUEST_METHOD']])) {
|
||||||
throw new RouteNotFoundException('Unknown HTTP method');
|
throw new RouteNotFoundException('Unknown HTTP method');
|
||||||
}
|
}
|
||||||
if ($this->basePath === '' || PathHelper::startsWith($this->url, $this->basePath)) {
|
$url = $this->url;
|
||||||
foreach ($this->routes[$_SERVER['REQUEST_METHOD']] as $route) {
|
if ($this->basePath !== '') {
|
||||||
if ($route->matches($this->url)) {
|
if (PathHelper::startsWith($url, $this->basePath)) {
|
||||||
return $route->call($di);
|
$url = trim(substr($url, strlen($this->basePath)), '/');
|
||||||
}
|
} else {
|
||||||
|
throw new RouteNotFoundException('No matching routes');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($this->routes[$_SERVER['REQUEST_METHOD']] as $route) {
|
||||||
|
if ($route->matches($url)) {
|
||||||
|
return $route->call($di);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new RouteNotFoundException('No matching routes');
|
throw new RouteNotFoundException('No matching routes');
|
||||||
|
Reference in New Issue
Block a user