From 48585f14abff97788e98a045aea9c9f63de9b3ec Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 25 Oct 2022 19:25:44 +0200 Subject: [PATCH] removed debug statements --- src/Service/Router.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Service/Router.php b/src/Service/Router.php index 8c631c0..3dca0bf 100644 --- a/src/Service/Router.php +++ b/src/Service/Router.php @@ -84,7 +84,7 @@ 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. + // (as it is a dynamic route) so I init the array just to make PHPStorm happy. $parameters = []; if (preg_match(pattern: $route->getRegex(), subject: $requestUri, matches: $matches)) { foreach ($route->getParameters() as $id => $parameter) { @@ -104,31 +104,21 @@ class Router public function path(string $routeName, array $vars = []) { foreach (array_merge($this->dynamicRoutes, $this->staticRoutes) as $route) { - if ($route->getName() == $routeName) { if ($vars) { // build route for dynamic routes - $route = $route->getRoute(); + $newRoute = $route->getRoute(); // replace placeholder with current values foreach ($vars as $key => $value) { - $route = str_replace(search: '{' . $key . '}', replace: $value, subject: $route); + $newRoute = str_replace(search: '{' . $key . '}', replace: $value, subject: $route); } - return $route; + return $newRoute; } else { return $route->getRoute(); } } } // no 404, this is reached only if the code is wrong - // TODO doesn't find the last route - /* - foreach (array_merge($this->dynamicRoutes, $this->staticRoutes) as $route) { - echo $route->getRoute() . '
'; - if ($routeName == $route->getRoute()) { - echo "equal"; - } - } - die("Missing Route: $routeName"); - */ + die("Missing Route: $routeName"); } } \ No newline at end of file