updated some comments
This commit is contained in:
parent
fddc58fb14
commit
0ed667d594
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue