diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index 0e94242..7d0ea01 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -112,8 +112,13 @@ class RouterBase { $routeNotAllowed = false; + $max = count($this->controllerUrlMap); + /* @var $route RouterEntry */ - foreach($this->controllerUrlMap as $route) { + for($i = 0; $i < $max; $i++) { + + $route = $this->controllerUrlMap[$i]; + $routeMatch = $route->matchRoute($this->request); if($routeMatch && !($routeMatch instanceof RouterGroup)) { @@ -270,8 +275,12 @@ class RouterBase { $c = ''; $method = null; + $max = count($this->controllerUrlMap); + /* @var $route RouterRoute */ - foreach($this->controllerUrlMap as $route) { + for($i = 0; $i < $max; $i++) { + + $route = $this->controllerUrlMap[$i]; // Check an alias exist, if the matches - use it if($route instanceof RouterRoute && strtolower($route->getAlias()) === strtolower($controller)) { @@ -292,7 +301,10 @@ class RouterBase { $c = ''; // No match has yet been found, let's try to guess what url that should be returned - foreach($this->controllerUrlMap as $route) { + for($i = 0; $i < $max; $i++) { + + $route = $this->controllerUrlMap[$i]; + if($route instanceof RouterRoute && !is_callable($route->getCallback()) && stripos($route->getCallback(), '@') !== false) { $c = $route->getClass(); } else if($route instanceof RouterController || $route instanceof RouterResource) { diff --git a/src/Pecee/SimpleRouter/RouterEntry.php b/src/Pecee/SimpleRouter/RouterEntry.php index 88af19b..ee7641b 100644 --- a/src/Pecee/SimpleRouter/RouterEntry.php +++ b/src/Pecee/SimpleRouter/RouterEntry.php @@ -301,8 +301,11 @@ abstract class RouterEntry { if(preg_match('/^'.$regex.'$/is', $url, $parameterValues)) { $parameters = array(); - if(count($parameterNames)) { - foreach($parameterNames as $name) { + $max = count($parameterNames); + + if(count($max)) { + for($i = 0; $i < $max; $i++) { + $name = $parameterNames[$i]; $parameterValue = (isset($parameterValues[$name['name']]) && !empty($parameterValues[$name['name']])) ? $parameterValues[$name['name']] : null; if($name['required'] && $parameterValue === null) { diff --git a/src/Pecee/SimpleRouter/RouterRoute.php b/src/Pecee/SimpleRouter/RouterRoute.php index fb8f143..83d5359 100644 --- a/src/Pecee/SimpleRouter/RouterRoute.php +++ b/src/Pecee/SimpleRouter/RouterRoute.php @@ -72,8 +72,10 @@ class RouterRoute extends RouterEntry { $parameters = $matches[1]; } - if(count($parameters)) { - foreach($parameters as $param) { + $max = count($parameters); + if($max) { + for($i = 0; $i < $max; $i++) { + $param = $parameters[$i]; $this->parameters[$param] = ''; } }