This commit is contained in:
William 2025-04-03 05:35:00 +00:00
parent baa9d854fb
commit 734111ad9d

View File

@ -14,6 +14,24 @@ abstract class Route
static array $groups = [ [ ] ];
static function getRelativeRequestPath(): string
{
static $request_url_path;
if (isset($request_url_path))
return $request_url_path;
$request_url_path = urldecode(strtok($_SERVER['REQUEST_URI'], '?'));
if (str_starts_with($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']))
$request_url_path = substr_replace(
urldecode(strtok($_SERVER['REQUEST_URI'], '?')), '', 0, strlen($_SERVER['SCRIPT_NAME'])
);
if ($request_url_path === '')
$request_url_path = '/';
return $request_url_path;
}
static function match(string $methods, string $url_path, callable $callback): void
{
if (!in_array(
@ -21,7 +39,7 @@ abstract class Route
array_map(strtoupper(...), explode('|', $methods))
)) return;
$request_url_path_parts = explode('/', urldecode(strtok($_SERVER['REQUEST_URI'], '?')));
$request_url_path_parts = explode('/', self::getRelativeRequestPath());
$url_path_parts = explode('/', self::$prefix . $url_path);
$callback_args = [];
@ -101,7 +119,7 @@ abstract class Route
throw new InvalidArgumentException('Argument callback must be of type callable.');
}
if (!str_starts_with(
$_SERVER['REQUEST_URI'],
self::getRelativeRequestPath(),
self::$prefix . $prefix
)) return;
self::$prefix = self::$prefix . $prefix;