From 0ed667d59459e1167402b03b6ca5941d3b43792d Mon Sep 17 00:00:00 2001 From: tracer Date: Mon, 24 Oct 2022 20:42:26 +0200 Subject: [PATCH] updated some comments --- src/Service/Router.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Service/Router.php b/src/Service/Router.php index 71c0e8e..eeb1424 100644 --- a/src/Service/Router.php +++ b/src/Service/Router.php @@ -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) {