mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 11:02:13 +00:00
[OPTIMISATION] Optimised more foreach loops to improve performance.
This commit is contained in:
@@ -112,8 +112,13 @@ class RouterBase {
|
|||||||
|
|
||||||
$routeNotAllowed = false;
|
$routeNotAllowed = false;
|
||||||
|
|
||||||
|
$max = count($this->controllerUrlMap);
|
||||||
|
|
||||||
/* @var $route RouterEntry */
|
/* @var $route RouterEntry */
|
||||||
foreach($this->controllerUrlMap as $route) {
|
for($i = 0; $i < $max; $i++) {
|
||||||
|
|
||||||
|
$route = $this->controllerUrlMap[$i];
|
||||||
|
|
||||||
$routeMatch = $route->matchRoute($this->request);
|
$routeMatch = $route->matchRoute($this->request);
|
||||||
|
|
||||||
if($routeMatch && !($routeMatch instanceof RouterGroup)) {
|
if($routeMatch && !($routeMatch instanceof RouterGroup)) {
|
||||||
@@ -270,8 +275,12 @@ class RouterBase {
|
|||||||
$c = '';
|
$c = '';
|
||||||
$method = null;
|
$method = null;
|
||||||
|
|
||||||
|
$max = count($this->controllerUrlMap);
|
||||||
|
|
||||||
/* @var $route RouterRoute */
|
/* @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
|
// Check an alias exist, if the matches - use it
|
||||||
if($route instanceof RouterRoute && strtolower($route->getAlias()) === strtolower($controller)) {
|
if($route instanceof RouterRoute && strtolower($route->getAlias()) === strtolower($controller)) {
|
||||||
@@ -292,7 +301,10 @@ class RouterBase {
|
|||||||
$c = '';
|
$c = '';
|
||||||
|
|
||||||
// No match has yet been found, let's try to guess what url that should be returned
|
// 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) {
|
if($route instanceof RouterRoute && !is_callable($route->getCallback()) && stripos($route->getCallback(), '@') !== false) {
|
||||||
$c = $route->getClass();
|
$c = $route->getClass();
|
||||||
} else if($route instanceof RouterController || $route instanceof RouterResource) {
|
} else if($route instanceof RouterController || $route instanceof RouterResource) {
|
||||||
|
|||||||
@@ -301,8 +301,11 @@ abstract class RouterEntry {
|
|||||||
if(preg_match('/^'.$regex.'$/is', $url, $parameterValues)) {
|
if(preg_match('/^'.$regex.'$/is', $url, $parameterValues)) {
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
|
|
||||||
if(count($parameterNames)) {
|
$max = count($parameterNames);
|
||||||
foreach($parameterNames as $name) {
|
|
||||||
|
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;
|
$parameterValue = (isset($parameterValues[$name['name']]) && !empty($parameterValues[$name['name']])) ? $parameterValues[$name['name']] : null;
|
||||||
|
|
||||||
if($name['required'] && $parameterValue === null) {
|
if($name['required'] && $parameterValue === null) {
|
||||||
|
|||||||
@@ -72,8 +72,10 @@ class RouterRoute extends RouterEntry {
|
|||||||
$parameters = $matches[1];
|
$parameters = $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($parameters)) {
|
$max = count($parameters);
|
||||||
foreach($parameters as $param) {
|
if($max) {
|
||||||
|
for($i = 0; $i < $max; $i++) {
|
||||||
|
$param = $parameters[$i];
|
||||||
$this->parameters[$param] = '';
|
$this->parameters[$param] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user