protected function RouteProvider::getRoutesByPath

protected RouteProvider::getRoutesByPath($path)

Get all routes which match a certain pattern.

Parameters

string $path: The route pattern to search for (contains % as placeholders).

Return value

\Symfony\Component\Routing\RouteCollection Returns a route collection of matching routes.

File

core/lib/Drupal/Core/Routing/RouteProvider.php, line 325

Class

RouteProvider
A Route Provider front-end for all Drupal-stored routes.

Namespace

Drupal\Core\Routing

Code

protected function getRoutesByPath($path) {
  // Split the path up on the slashes, ignoring multiple slashes in a row
  // or leading or trailing slashes.
  $parts = preg_split('@/+@', $path, NULL, PREG_SPLIT_NO_EMPTY);

  $collection = new RouteCollection();

  $ancestors = $this->getCandidateOutlines($parts);
  if (empty($ancestors)) {
    return $collection;
  }

  // The >= check on number_parts allows us to match routes with optional
  // trailing wildcard parts as long as the pattern matches, since we
  // dump the route pattern without those optional parts.
  try {
    $routes = $this->connection->query("SELECT name, route, fit FROM {" . $this->connection->escapeTable($this->tableName) . "} WHERE pattern_outline IN ( :patterns[] ) AND number_parts >= :count_parts", array(
      ':patterns[]' => $ancestors, ':count_parts' => count($parts),
    ))
      ->fetchAll(\PDO::FETCH_ASSOC);
  }
  catch (\Exception $e) {
    $routes = [];
  }

  // We sort by fit and name in PHP to avoid a SQL filesort.
  usort($routes, array($this, 'routeProviderRouteCompare'));

  foreach ($routes as $row) {
    $collection->add($row['name'], unserialize($row['route']));
  }

  return $collection;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Routing!RouteProvider.php/function/RouteProvider::getRoutesByPath/8.1.x