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)
|
||||
{
|
||||
if (PathHelper::startsWith($this->url, $basePath)) {
|
||||
$this->url = trim(substr($this->url, strlen($basePath)), '/');
|
||||
}
|
||||
$this->basePath = $basePath;
|
||||
}
|
||||
|
||||
@@ -67,11 +64,17 @@ class Router
|
||||
if (!isset($this->routes[$_SERVER['REQUEST_METHOD']])) {
|
||||
throw new RouteNotFoundException('Unknown HTTP method');
|
||||
}
|
||||
if ($this->basePath === '' || PathHelper::startsWith($this->url, $this->basePath)) {
|
||||
foreach ($this->routes[$_SERVER['REQUEST_METHOD']] as $route) {
|
||||
if ($route->matches($this->url)) {
|
||||
return $route->call($di);
|
||||
}
|
||||
$url = $this->url;
|
||||
if ($this->basePath !== '') {
|
||||
if (PathHelper::startsWith($url, $this->basePath)) {
|
||||
$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');
|
||||
|
Reference in New Issue
Block a user