Update Route.php

This commit is contained in:
William 2025-04-02 13:05:10 +00:00
parent 1e81b72c20
commit fc2754adaf

View File

@ -14,21 +14,6 @@ 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 = 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(
@ -36,7 +21,7 @@ abstract class Route
array_map(strtoupper(...), explode('|', $methods))
)) return;
$request_url_path_parts = explode('/', self::getRelativeRequestPath());
$request_url_path_parts = explode('/', urldecode(strtok($_SERVER['REQUEST_URI'], '?')));
$url_path_parts = explode('/', self::$prefix . $url_path);
$callback_args = [];
@ -116,7 +101,7 @@ abstract class Route
throw new InvalidArgumentException('Argument callback must be of type callable.');
}
if (!str_starts_with(
self::getRelativeRequestPath(),
$_SERVER['REQUEST_URI'],
self::$prefix . $prefix
)) return;
self::$prefix = self::$prefix . $prefix;