removed debug statements
This commit is contained in:
parent
47439fe358
commit
48585f14ab
|
@ -84,7 +84,7 @@ class Router
|
||||||
|
|
||||||
foreach ($this->dynamicRoutes as $route) {
|
foreach ($this->dynamicRoutes as $route) {
|
||||||
// PHPStorm doesn't know that $parameters are always available,
|
// 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 = [];
|
$parameters = [];
|
||||||
if (preg_match(pattern: $route->getRegex(), subject: $requestUri, matches: $matches)) {
|
if (preg_match(pattern: $route->getRegex(), subject: $requestUri, matches: $matches)) {
|
||||||
foreach ($route->getParameters() as $id => $parameter) {
|
foreach ($route->getParameters() as $id => $parameter) {
|
||||||
|
@ -104,31 +104,21 @@ class Router
|
||||||
public function path(string $routeName, array $vars = [])
|
public function path(string $routeName, array $vars = [])
|
||||||
{
|
{
|
||||||
foreach (array_merge($this->dynamicRoutes, $this->staticRoutes) as $route) {
|
foreach (array_merge($this->dynamicRoutes, $this->staticRoutes) as $route) {
|
||||||
|
|
||||||
if ($route->getName() == $routeName) {
|
if ($route->getName() == $routeName) {
|
||||||
if ($vars) {
|
if ($vars) {
|
||||||
// build route for dynamic routes
|
// build route for dynamic routes
|
||||||
$route = $route->getRoute();
|
$newRoute = $route->getRoute();
|
||||||
// replace placeholder with current values
|
// replace placeholder with current values
|
||||||
foreach ($vars as $key => $value) {
|
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 {
|
} else {
|
||||||
return $route->getRoute();
|
return $route->getRoute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no 404, this is reached only if the code is wrong
|
// 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");
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue