Skip to content

Commit

Permalink
better basePath support
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Jul 18, 2019
1 parent d836360 commit 9dde583
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 11 additions & 5 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4809,14 +4809,20 @@ private function detectBasePath(string $basePath): string
if ($basePath) {
return $basePath;
}
if (isset($_SERVER['PATH_INFO'])) {
if (isset($_SERVER['REQUEST_URI'])) {
$fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
$path = $_SERVER['PATH_INFO'];
if (substr($fullPath, -1 * strlen($path)) == $path) {
return substr($fullPath, 0, -1 * strlen($path));
if (isset($_SERVER['PATH_INFO'])) {
$path = $_SERVER['PATH_INFO'];
if (!$path) {
return $_SERVER['PHP_SELF'];
}
if (substr($fullPath, -1 * strlen($path)) == $path) {
return substr($fullPath, 0, -1 * strlen($path));
}
}
return $fullPath;
}
return $_SERVER['PHP_SELF'];
return '/';
}

private function loadPathTree(): PathTree
Expand Down
19 changes: 12 additions & 7 deletions src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ private function detectBasePath(string $basePath): string
if ($basePath) {
return $basePath;
}
$fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
$path = $_SERVER['PATH_INFO'];
if (!$path) {
if (isset($_SERVER['REQUEST_URI'])) {
$fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
if (isset($_SERVER['PATH_INFO'])) {
$path = $_SERVER['PATH_INFO'];
if (!$path) {
return $_SERVER['PHP_SELF'];
}
if (substr($fullPath, -1 * strlen($path)) == $path) {
return substr($fullPath, 0, -1 * strlen($path));
}
}
return $fullPath;
}
if (substr($fullPath, -1 * strlen($path)) == $path) {
return substr($fullPath, 0, -1 * strlen($path));
}
return $_SERVER['PHP_SELF'];
return '/';
}

private function loadPathTree(): PathTree
Expand Down

0 comments on commit 9dde583

Please sign in to comment.