updated some comments

This commit is contained in:
tracer 2022-10-24 20:42:26 +02:00
parent fddc58fb14
commit 0ed667d594
1 changed files with 4 additions and 1 deletions

View File

@ -45,6 +45,7 @@ class Router
// create regex for route:
$regex = preg_replace(pattern: '/{.+?}/', replacement: '([a-zA-Z0-9]*)', subject: $route);
// escape \ in regex
$regex = '/^' . str_replace(search: "/", replace: '\\/', subject: $regex) . '$/i';
$route = new Route(name: $name, route: $route, regEx: $regex, parameters: $parameters, callback: $callback);
@ -64,7 +65,7 @@ class Router
$requestUri = $_SERVER['REQUEST_URI'];
/*
* Static routes have preference over dynamic ones, so
* Static routes have precedence over dynamic ones, so
* /admin/user/add to add and
* /admin/user/{name} to edit is possible.
* A user named "add" of course not :)
@ -82,6 +83,8 @@ class Router
}
foreach ($this->dynamicRoutes as $route) {
// PHPStorm doesn't know that $parameters are always available,
// (as it is a dynamic route) so the init the array just to mke PHPstorm happy.
$parameters = [];
if (preg_match(pattern: $route->getRegex(), subject: $requestUri, matches: $matches)) {
foreach ($route->getParameters() as $id => $parameter) {