🧼 Clean up routing behavior with new trim method

This commit is contained in:
Splashsky 2021-07-16 07:14:33 -05:00
parent 1393e0face
commit d0bef18c59

View File

@ -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;