mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 21:22:17 +00:00
[OPTIMISATION] Optimised routes loop.
This commit is contained in:
@@ -38,13 +38,17 @@ class RouterBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processRoutes(array $routes, array $settings = array(), array $prefixes = array(), $backstack = false, $group = null) {
|
protected function processRoutes(array $routes, array $settings = array(), array $prefixes = array(), $backStack = false, $group = null) {
|
||||||
// Loop through each route-request
|
// Loop through each route-request
|
||||||
|
|
||||||
$activeGroup = null;
|
$activeGroup = null;
|
||||||
|
|
||||||
|
$routesCount = count($routes);
|
||||||
|
|
||||||
/* @var $route RouterEntry */
|
/* @var $route RouterEntry */
|
||||||
foreach($routes as $route) {
|
for($i = 0; $i < $routesCount; $i++) {
|
||||||
|
|
||||||
|
$route = $routes[$i];
|
||||||
|
|
||||||
$route->setGroup($group);
|
$route->setGroup($group);
|
||||||
|
|
||||||
@@ -68,7 +72,7 @@ class RouterBase {
|
|||||||
$route->addSettings($settings);
|
$route->addSettings($settings);
|
||||||
|
|
||||||
if(!($route instanceof RouterGroup)) {
|
if(!($route instanceof RouterGroup)) {
|
||||||
if(is_array($newPrefixes) && count($newPrefixes) && $backstack) {
|
if(is_array($newPrefixes) && count($newPrefixes) && $backStack) {
|
||||||
$route->setUrl( join('/', $newPrefixes) . $route->getUrl() );
|
$route->setUrl( join('/', $newPrefixes) . $route->getUrl() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,11 +88,11 @@ class RouterBase {
|
|||||||
$this->currentRoute = null;
|
$this->currentRoute = null;
|
||||||
|
|
||||||
if(count($this->backstack)) {
|
if(count($this->backstack)) {
|
||||||
$backstack = $this->backstack;
|
$backStack = $this->backstack;
|
||||||
$this->backstack = array();
|
$this->backstack = array();
|
||||||
|
|
||||||
// Route any routes added to the backstack
|
// Route any routes added to the backstack
|
||||||
$this->processRoutes($backstack, $mergedSettings, $newPrefixes, true, $activeGroup);
|
$this->processRoutes($backStack, $mergedSettings, $newPrefixes, true, $activeGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user