@@ -8071,7 +8071,7 @@ class SimpleRouter implements Router
8071
8071
8072
8072
public function __construct(string $basePath, Responder $responder, Cache $cache, int $ttl)
8073
8073
{
8074
- $this->basePath = rtrim($basePath, '/');
8074
+ $this->basePath = rtrim($basePath, '/') ?: rtrim($this->detectBasePath(), '/'); ;
8075
8075
$this->responder = $responder;
8076
8076
$this->cache = $cache;
8077
8077
$this->ttl = $ttl;
@@ -8081,18 +8081,18 @@ public function __construct(string $basePath, Responder $responder, Cache $cache
8081
8081
$this->middlewares = array();
8082
8082
}
8083
8083
8084
- private function detectBasePath(ServerRequestInterface $request ): string
8084
+ private function detectBasePath(): string
8085
8085
{
8086
- $serverParams = $request->getServerParams();
8087
- if (isset($serverParams['REQUEST_URI'])) {
8088
- $fullPath = urldecode(explode('?', $serverParams['REQUEST_URI'])[0]);
8089
- if (isset($serverParams['PATH_INFO'])) {
8090
- $path = $serverParams['PATH_INFO'];
8086
+ if (isset($_SERVER['REQUEST_URI'])) {
8087
+ $fullPath = urldecode(explode('?', $_SERVER['REQUEST_URI'])[0]);
8088
+ if (isset($_SERVER['PATH_INFO'])) {
8089
+ $path = $_SERVER['PATH_INFO'];
8091
8090
if (substr($fullPath, -1 * strlen($path)) == $path) {
8092
8091
return substr($fullPath, 0, -1 * strlen($path));
8093
8092
}
8094
8093
}
8095
- if ('/' . basename(__FILE__) == $fullPath) {
8094
+ $path = '/' . basename(__FILE__);
8095
+ if (substr($fullPath, -1 * strlen($path)) == $path) {
8096
8096
return $fullPath;
8097
8097
}
8098
8098
}
@@ -8133,9 +8133,6 @@ public function load(Middleware $middleware) /*: void*/
8133
8133
8134
8134
public function route(ServerRequestInterface $request): ResponseInterface
8135
8135
{
8136
- if (!$this->basePath) {
8137
- $this->basePath = rtrim($this->detectBasePath($request), '/');
8138
- }
8139
8136
if ($this->registration) {
8140
8137
$data = gzcompress(json_encode($this->routes, JSON_UNESCAPED_UNICODE));
8141
8138
$this->cache->set('PathTree', $data, $this->ttl);
0 commit comments