removed debug statements

This commit is contained in:
tracer 2022-10-25 19:25:44 +02:00
parent 47439fe358
commit 48585f14ab
1 changed files with 5 additions and 15 deletions

View File

@ -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() . '<br>';
if ($routeName == $route->getRoute()) {
echo "equal";
}
}
die("Missing Route: $routeName");
*/
die("Missing Route: $routeName");
}
}