Skip to content

Commit

Permalink
Merge pull request #716 from LuckyCyborg/master
Browse files Browse the repository at this point in the history
Support the Deep Grouping into Routing
  • Loading branch information
daveismynamecom committed Apr 10, 2016
2 parents cd6e2db + 654ee21 commit d3b87b6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions system/Core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,27 @@ public function addRoute($method, $route, $callback = null)
$pattern = ltrim($route, '/');

if (! empty(self::$routeGroups)) {
$prefixes = array();
$parts = array();
$namespace = '';

foreach (self::$routeGroups as $group) {
// Add the current prefix to the prefixes list.
array_push($prefixes, $group['prefix']);
array_push($parts, $group['prefix']);
// Keep always the last Controller's namespace.
$namespace = $group['namespace'];
}

if (! empty($pattern)) {
array_push($parts, $pattern);
}

// Adjust the Route PATTERN.
if(! empty($prefixes)) {
$pattern = implode('/', $prefixes) .'/' .$pattern;
if (! empty($parts)) {
$pattern = implode('/', $parts);
}

// Adjust the Route CALLBACK, when it is not a Closure.
if(! empty($namespace) && ! is_object($callback)) {
if (! empty($namespace) && ! is_object($callback)) {
$callback = $namespace .'\\' .$callback;
}
}
Expand Down

0 comments on commit d3b87b6

Please sign in to comment.