mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
[OPTIMISATION] Optimised more foreach loops to improve performance.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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] = '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user