Skip to content

Commit

Permalink
optimize routing
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 3, 2016
1 parent dd29c00 commit c8ed0c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Illuminate/Routing/Matching/UriValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public function matches(Route $route, Request $request)
{
$path = $request->path() == '/' ? '/' : '/'.$request->path();

if ('' !== $route->getCompiled()->getStaticPrefix() &&
0 !== strpos($path, $route->getCompiled()->getStaticPrefix())) {
return false;
}

return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
}
}
8 changes: 7 additions & 1 deletion src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ public function matches(Request $request, $includingMethod = true)
*/
protected function compileRoute()
{
if ($this->compiled) {
return;
}

$optionals = $this->extractOptionalParameters();

$uri = preg_replace('/\{(\w+?)\?\}/', '{$1}', $this->uri);
Expand Down Expand Up @@ -995,7 +999,9 @@ public function prepareForSerialization()
throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure.");
}

unset($this->router, $this->container, $this->compiled);
$this->compileRoute();

unset($this->router, $this->container);
}

/**
Expand Down

0 comments on commit c8ed0c3

Please sign in to comment.