Matches a request against multiple routes.
\Symfony\Component\HttpFoundation\Request $request: A Request object against which to match.
\Symfony\Component\Routing\RouteCollection A RouteCollection of matched routes.
Overrides InitialMatcherInterface::matchRequestPartial
public function matchRequestPartial(Request $request) {
// The 'system_path' has language prefix stripped and path alias resolved,
// whereas getPathInfo() returns the requested path. In Drupal, the request
// always contains a system_path attribute, but this component may get
// adopted by non-Drupal projects. Some unit tests also skip initializing
// 'system_path'.
// @todo Consider abstracting this to a separate object.
if ($request->attributes
->has('system_path')) {
// system_path never has leading or trailing slashes.
$path = '/' . $request->attributes
->get('system_path');
}
else {
// getPathInfo() always has leading slash, and might or might not have a
// trailing slash.
$path = rtrim($request
->getPathInfo(), '/');
}
$parts = array_slice(array_filter(explode('/', $path)), 0, MatcherDumper::MAX_PARTS);
$ancestors = $this
->getCandidateOutlines($parts);
$routes = $this->connection
->query("SELECT name, route FROM {" . $this->connection
->escapeTable($this->tableName) . "} WHERE pattern_outline IN (:patterns) ORDER BY fit", array(
':patterns' => $ancestors,
))
->fetchAllKeyed();
$collection = new RouteCollection();
foreach ($routes as $name => $route) {
$route = unserialize($route);
if (preg_match($route
->compile()
->getRegex(), $path, $matches)) {
$collection
->add($name, $route);
}
}
if (!count($collection)) {
throw new ResourceNotFoundException();
}
return $collection;
}