Skip to content

Commit 9dde583

Browse files
committed
better basePath support
1 parent d836360 commit 9dde583

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

api.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4809,14 +4809,20 @@ private function detectBasePath(string $basePath): string
48094809
if ($basePath) {
48104810
return $basePath;
48114811
}
4812-
if (isset($_SERVER['PATH_INFO'])) {
4812+
if (isset($_SERVER['REQUEST_URI'])) {
48134813
$fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
4814-
$path = $_SERVER['PATH_INFO'];
4815-
if (substr($fullPath, -1 * strlen($path)) == $path) {
4816-
return substr($fullPath, 0, -1 * strlen($path));
4814+
if (isset($_SERVER['PATH_INFO'])) {
4815+
$path = $_SERVER['PATH_INFO'];
4816+
if (!$path) {
4817+
return $_SERVER['PHP_SELF'];
4818+
}
4819+
if (substr($fullPath, -1 * strlen($path)) == $path) {
4820+
return substr($fullPath, 0, -1 * strlen($path));
4821+
}
48174822
}
4823+
return $fullPath;
48184824
}
4819-
return $_SERVER['PHP_SELF'];
4825+
return '/';
48204826
}
48214827

48224828
private function loadPathTree(): PathTree

src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@ private function detectBasePath(string $basePath): string
4141
if ($basePath) {
4242
return $basePath;
4343
}
44-
$fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
45-
$path = $_SERVER['PATH_INFO'];
46-
if (!$path) {
44+
if (isset($_SERVER['REQUEST_URI'])) {
45+
$fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
46+
if (isset($_SERVER['PATH_INFO'])) {
47+
$path = $_SERVER['PATH_INFO'];
48+
if (!$path) {
49+
return $_SERVER['PHP_SELF'];
50+
}
51+
if (substr($fullPath, -1 * strlen($path)) == $path) {
52+
return substr($fullPath, 0, -1 * strlen($path));
53+
}
54+
}
4755
return $fullPath;
4856
}
49-
if (substr($fullPath, -1 * strlen($path)) == $path) {
50-
return substr($fullPath, 0, -1 * strlen($path));
51-
}
52-
return $_SERVER['PHP_SELF'];
57+
return '/';
5358
}
5459

5560
private function loadPathTree(): PathTree

0 commit comments

Comments
 (0)