Skip to content

Commit

Permalink
fix route match
Browse files Browse the repository at this point in the history
  • Loading branch information
aviggngyv committed Dec 21, 2017
1 parent 6130b29 commit ee5a8c8
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions core/lib/Hunter/App/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,30 +339,32 @@ protected function buildRouters($container) {

foreach ($this->routeList as $module_routers) {
foreach ($module_routers as $name => $route_info) {
if($route_info['path'] == request_uri()){
if(isset($route_info['requirements']['_permission'])){
$this->routePermission[$route_info['path']] = $route_info['requirements']['_permission'];
}

if(isset($route_info['options'])){
$this->routeOptions[$route_info['path']] = $route_info['options'];
}
if($curpath = preg_replace("/\{.*\}/", "([^/]+)", $route_info['path'])){
if(preg_match("~^(?|".$curpath.")$~", request_uri(), $matches)){
if(isset($route_info['requirements']['_permission'])){
$this->routePermission[$route_info['path']] = $route_info['requirements']['_permission'];
}

if(isset($route_info['defaults']['_title'])){
$this->routeTitles[$route_info['path']] = $route_info['defaults']['_title'];
}
if(isset($route_info['options'])){
$this->routeOptions[$route_info['path']] = $route_info['options'];
}

$this->routeNames[$route_info['path']] = $name;
if(isset($route_info['defaults']['_title'])){
$this->routeTitles[$route_info['path']] = $route_info['defaults']['_title'];
}

$route = $routers->map(['GET','POST'], $route_info['path'], $route_info['defaults']['_controller']);
if(isset($route_info['requirements']['_permission']) && !empty($route_info['requirements']['_permission'])){
if(is_array($route_info['requirements']['_permission'])){
foreach (array_reverse($route_info['requirements']['_permission']) as $midd) {
$middleware = [$this->container->get($midd), 'handle'];
$route->middleware($middleware);
$this->routeNames[$route_info['path']] = $name;

$route = $routers->map(['GET','POST'], $route_info['path'], $route_info['defaults']['_controller']);
if(isset($route_info['requirements']['_permission']) && !empty($route_info['requirements']['_permission'])){
if(is_array($route_info['requirements']['_permission'])){
foreach (array_reverse($route_info['requirements']['_permission']) as $midd) {
$middleware = [$this->container->get($midd), 'handle'];
$route->middleware($middleware);
}
}else {
$route->middleware([$this->container->get($route_info['requirements']['_permission']), 'handle']);
}
}else {
$route->middleware([$this->container->get($route_info['requirements']['_permission']), 'handle']);
}
}
}
Expand Down

0 comments on commit ee5a8c8

Please sign in to comment.