You are here

protected function MongodbRouterRouteProvider::getRoutesByPath in MongoDB 8

Get all routes which match a certain pattern.

Parameters

string $path: The route pattern to search for.

Return value

\Symfony\Component\Routing\RouteCollection Returns a route collection of matching routes. The collection may be empty and will be sorted from highest to lowest fit (match of path parts) and then in ascending order by route name for routes with the same fit.

Overrides RouteProvider::getRoutesByPath

File

src/MongodbRouterRouteProvider.php, line 77
Contains Drupal\mongodb\MongodbRouterRouteProvider.

Class

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

Namespace

Drupal\mongodb

Code

protected function getRoutesByPath($path) {

  // Filter out each empty value, though allow '0' and 0, which would be
  // filtered out by empty().
  $parts = array_values(array_filter(explode('/', $path), function ($value) {
    return $value !== NULL && $value !== '';
  }));
  $ancestors = $this
    ->getCandidateOutlines($parts);
  $routes = $this->mongo
    ->get($this->tableName)
    ->find(array(
    'pattern_outline' => array(
      '$in' => $ancestors,
    ),
  ))
    ->sort(array(
    'fit' => -1,
    '_id' => 1,
  ));
  $collection = new RouteCollection();
  foreach ($routes as $name => $route_array) {
    $route = $this
      ->getRouteFromArray($route_array);
    if (preg_match($route
      ->compile()
      ->getRegex(), $path, $matches)) {
      $collection
        ->add($name, $route);
    }
  }
  return $collection;
}