Skip to content

Commit a489e7b

Browse files
committed
better basePath support
1 parent ddf37c2 commit a489e7b

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

api.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4810,13 +4810,16 @@ private function detectBasePath(string $basePath): string
48104810
return $basePath;
48114811
}
48124812
if (isset($_SERVER['PATH_INFO'])) {
4813-
$fullPath = array_shift(explode('?',$_SERVER['REQUEST_URI']));
4813+
$fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
48144814
$path = $_SERVER['PATH_INFO'];
4815-
if (substr($fullPath, -1*strlen($path)) == $path) {
4816-
return substr($fullPath, 0, -1*strlen($path));
4815+
if (!$path) {
4816+
return $_SERVER['PHP_SELF'];
4817+
}
4818+
if (substr($fullPath, -1 * strlen($path)) == $path) {
4819+
return substr($fullPath, 0, -1 * strlen($path));
48174820
}
48184821
}
4819-
return '';
4822+
return '/';
48204823
}
48214824

48224825
private function loadPathTree(): PathTree
@@ -4870,15 +4873,10 @@ private function getRouteNumbers(ServerRequestInterface $request): array
48704873

48714874
private function removeBasePath(ServerRequestInterface $request): ServerRequestInterface
48724875
{
4873-
if ($this->basePath) {
4874-
$path = $request->getUri()->getPath();
4875-
$basePath = rtrim($this->basePath, '/');
4876-
if (substr($path, 0, strlen($basePath)) == $basePath) {
4877-
$path = substr($path, strlen($basePath));
4878-
$request = $request->withUri($request->getUri()->withPath($path));
4879-
}
4880-
} elseif (isset($_SERVER['PATH_INFO'])) {
4881-
$path = $_SERVER['PATH_INFO'];
4876+
$path = $request->getUri()->getPath();
4877+
$basePath = rtrim($this->basePath, '/');
4878+
if (substr($path, 0, strlen($basePath)) == $basePath) {
4879+
$path = substr($path, strlen($basePath));
48824880
$request = $request->withUri($request->getUri()->withPath($path));
48834881
}
48844882
return $request;

0 commit comments

Comments
 (0)