You are here

protected function RouteProvider::getRoutesByPath in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Routing/RouteProvider.php \Drupal\Core\Routing\RouteProvider::getRoutesByPath()

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.

2 calls to RouteProvider::getRoutesByPath()
RouteProvider::getRouteCollectionForRequest in core/lib/Drupal/Core/Routing/RouteProvider.php
Finds routes that may potentially match the request.
RouteProvider::getRoutesByPattern in core/lib/Drupal/Core/Routing/RouteProvider.php
Get all routes which match a certain pattern.

File

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

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.
  $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);

  // 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;
}