|
|
|
@ -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,13 +64,19 @@ class Router
|
|
|
|
|
if (!isset($this->routes[$_SERVER['REQUEST_METHOD']])) {
|
|
|
|
|
throw new RouteNotFoundException('Unknown HTTP method');
|
|
|
|
|
}
|
|
|
|
|
if ($this->basePath === '' || PathHelper::startsWith($this->url, $this->basePath)) {
|
|
|
|
|
$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($this->url)) {
|
|
|
|
|
if ($route->matches($url)) {
|
|
|
|
|
return $route->call($di);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new RouteNotFoundException('No matching routes');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|