Skip to content

Commit

Permalink
Merge remote-tracking branch 'gmanricks/refactor_groups' into release…
Browse files Browse the repository at this point in the history
…-2.3.0
  • Loading branch information
= committed Jul 8, 2013
2 parents 9212ea5 + 5d18374 commit 409d8a3
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Slim/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,13 @@ public function getMatchedRoutes($httpMethod, $resourceUri, $reload = false)
public function map(\Slim\Route $route)
{
list($groupPattern, $groupMiddleware) = $this->processGroups();
if (count($this->routeGroups) > 0) {
$route->setPattern($groupPattern . $route->getPattern());
}

$route->setPattern($groupPattern . $route->getPattern());
$this->routes[] = $route;

if (count($this->routeGroups) > 0) {
foreach ($groupMiddleware as $middlewareArr) {
if (is_array($middlewareArr)) {
foreach ($middlewareArr as $middleware) {
$route->setMiddleware($middleware);
}
}
}

foreach ($groupMiddleware as $middleware) {
$route->setMiddleware($middleware);
}
}

Expand All @@ -153,7 +147,9 @@ protected function processGroups()
foreach ($this->routeGroups as $group) {
$k = key($group);
$pattern .= $k;
array_push($middleware, $group[$k]);
if (is_array($group[$k])) {
$middleware = array_merge($middleware, $group[$k]);
}
}
return array($pattern, $middleware);
}
Expand All @@ -164,7 +160,7 @@ protected function processGroups()
* @param array|null $middleware Optional parameter array of middleware
* @return int The index of the new group
*/
public function pushGroup($group, $middleware = null)
public function pushGroup($group, $middleware = array())
{
return array_push($this->routeGroups, array($group => $middleware));
}
Expand Down

0 comments on commit 409d8a3

Please sign in to comment.