private function findRouteRecursively(&$pathParts, $index, &$method)
{
// Base Case - We've gone to the end of the path.
if ($index < 0) {
$result = new RoutingResult();
if (!empty($this->m)) {
// Leaf, now check HTTP Method Match
if (isset($this->m[$method])) {
$result->routeExists = true;
$result->methodIsSupported = true;
$result->route = $this->m[$method]->toRoute();
} else {
$result->routeExists = true;
$routes = array_values($this->m);
$result->route = $routes[0]->toRoute();
$result->route->methods = array_values($this->m);
$result->methodIsSupported = false;
$result->acceptableMethods = array_keys($this->m);
}
} else {
// Non-leaf, no match
$result->routeExists = false;
}
return $result;
}
// Find a child for the next part of the path.
$nextPart =& $pathParts[$index];
$result = new RoutingResult();
// Check for a static match
if (isset($this->s[$nextPart])) {
$child = $this->s[$nextPart];
$result = $child->findRouteRecursively($pathParts, $index - 1, $method);
}
if (!$result->routeExists && !empty($this->p)) {
foreach ($this->p as $child) {
if ($child->matches($nextPart)) {
$result = $child->findRouteRecursively($pathParts, $index - 1, $method);
if ($result->routeExists) {
if ($child->c != '') {
$result->arguments[$child->c] = urldecode($nextPart);
}
return $result;
}
}
}
}
return $result;
}