Skip to content
Permalink
Browse files

Only sort routes when new paths are added.

Remove complexity and nested statements where possible.
  • Loading branch information...
markstory committed Jul 5, 2014
1 parent 78a4a81 commit 839282cc3e6a7866d4cd0ccbf8a9728a570fe37a
Showing with 16 additions and 25 deletions.
  1. +16 −25 src/Routing/RouteCollection.php
@@ -78,14 +78,6 @@ public function add(Route $route, $options) {
$this->_paths[$path][] = $route;
/*
// Index scopes by path (for parsing)
if (empty(static::$_pathScopes[$path])) {
static::$_pathScopes[$path] = $collection;
krsort(static::$_pathScopes);
} else {
static::$_pathScopes[$path]->merge($collection);
}
// Index scopes by key params (for reverse routing).
$plugin = isset($params['plugin']) ? $params['plugin'] : '';
$prefix = isset($params['prefix']) ? $params['prefix'] : '';
@@ -104,27 +96,26 @@ public function add(Route $route, $options) {
* @return array An array of request parameters parsed from the url.
*/
public function parse($url) {
krsort($this->_paths);
foreach ($this->_paths as $path => $collection) {
if (strpos($url, $path) !== 0) {
continue;
foreach (array_keys($this->_paths) as $path) {
if (strpos($url, $path) === 0) {
break;
}
}
$queryParameters = null;
if (strpos($url, '?') !== false) {
list($url, $queryParameters) = explode('?', $url, 2);
parse_str($queryParameters, $queryParameters);
$queryParameters = null;
if (strpos($url, '?') !== false) {
list($url, $queryParameters) = explode('?', $url, 2);
parse_str($queryParameters, $queryParameters);
}
foreach ($this->_paths[$path] as $route) {
$r = $route->parse($url);
if ($r === false) {
continue;
}
foreach ($collection as $route) {
$r = $route->parse($url);
if ($r === false) {
continue;
}
if ($queryParameters) {
$r['?'] = $queryParameters;
}
return $r;
if ($queryParameters) {
$r['?'] = $queryParameters;
}
return $r;
}
throw new MissingRouteException(['url' => $url]);
}

0 comments on commit 839282c

Please sign in to comment.
You can’t perform that action at this time.