Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,23 @@ public static function setBasePath($serverBasePath)
*/
public static function getCurrentUri(): string
{
// Get the current Request URI and remove rewrite base path from it (= allows one to run the router in a sub folder)
$uri = substr(rawurldecode($_SERVER['REQUEST_URI']), strlen(static::getBasePath()));
$basePath = static::getBasePath();
$requestUri = rawurldecode($_SERVER['REQUEST_URI']);

// Early exit If base path doesn't match
if (strncmp($requestUri, $basePath, strlen($basePath)) !== 0) {
if (!static::$notFoundHandler) {
static::$notFoundHandler = function () {
\Leaf\Exception\General::default404();
};
}
static::invoke(static::$notFoundHandler);
}

if (strstr($uri, '?')) {
$uri = substr($uri, 0, strpos($uri, '?'));
// Get the current Request URI and remove rewrite base path from it (= allows one to run the router in a sub folder)
$uri = substr($requestUri, strlen($basePath)) ?: '/';
if (($queryPos = strpos($uri, '?')) !== false) {
$uri = substr($uri, 0, $queryPos);
}

return '/' . trim($uri, '/');
Expand Down