Skip to content

Commit

Permalink
Do not check for uri chunks to parse route
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Jul 13, 2016
1 parent febcef3 commit c2a8f39
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/Cortex/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function parseRoutes(UriInterface $uri, $httpMethod)
/** @var \Brain\Cortex\Route\RouteInterface $route */
foreach ($iterator as $route) {
$route = $this->sanitizeRouteMethod($this->groups->mergeGroup($route), $httpMethod);
if (! $this->validateRoute($route, $uri, $httpMethod)) {
if (! $this->validateRoute($route, $httpMethod)) {
continue;
}

Expand Down Expand Up @@ -178,25 +178,20 @@ private function sanitizeRouteMethod(RouteInterface $route, $httpMethod)

/**
* @param \Brain\Cortex\Route\RouteInterface $route
* @param \Brain\Cortex\Uri\UriInterface $uri
* @param $httpMethod
* @return bool
*/
private function validateRoute(RouteInterface $route, UriInterface $uri, $httpMethod)
private function validateRoute(RouteInterface $route, $httpMethod)
{
$id = $route->id();
$path = trim($route['path'], '/');
if (count($uri->chunks()) !== (substr_count($path, '/') + 1)) {
return false;
}
$method = (array)$route['method'];
$handler = $route['handler'];

return
is_string($id)
&& $id
&& filter_var($path, FILTER_SANITIZE_URL) === $path
&& in_array($httpMethod, $method, true)
&& in_array($httpMethod, (array) $route['method'], true)
&& (is_callable($handler) || $handler instanceof ControllerInterface);
}

Expand Down

0 comments on commit c2a8f39

Please sign in to comment.