🧼 Clean up routing behavior with new trim method
This commit is contained in:
parent
1393e0face
commit
d0bef18c59
|
@ -27,7 +27,7 @@ class Router
|
|||
}
|
||||
|
||||
self::$routes[] = [
|
||||
'route' => $route,
|
||||
'route' => self::trimRoute($route),
|
||||
'action' => $action,
|
||||
'methods' => $methods
|
||||
];
|
||||
|
@ -102,6 +102,12 @@ class Router
|
|||
self::$defaultConstraint = $constraint;
|
||||
}
|
||||
|
||||
private static function trimRoute(string $route): string
|
||||
{
|
||||
$route = trim(trim($route), '/');
|
||||
return "/$route";
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a callable that defines routes, and adds a prefix to them.
|
||||
*
|
||||
|
@ -182,12 +188,7 @@ class Router
|
|||
$basePath = rtrim($basePath, '/');
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
|
||||
$path = urldecode(rtrim($uri, '/'));
|
||||
|
||||
// If the path is empty (no slash in URI) place one to satisfy the root route ('/')
|
||||
if (empty($path)) {
|
||||
$path = '/';
|
||||
}
|
||||
$path = urldecode(self::trimRoute($uri));
|
||||
|
||||
$pathMatchFound = false;
|
||||
$routeMatchFound = false;
|
||||
|
|
Loading…
Reference in New Issue
Block a user