public function RouteProvider::getCandidateOutlines

Returns an array of path pattern outlines that could match the path parts.

Parameters

array $parts: The parts of the path for which we want candidates.

Return value

array An array of outlines that could match the specified path parts.

1 call to RouteProvider::getCandidateOutlines()
RouteProvider::getRouteCollectionForRequest in drupal/core/lib/Drupal/Core/Routing/RouteProvider.php
Finds routes that may potentially match the request.

File

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

Class

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

Namespace

Drupal\Core\Routing

Code

public function getCandidateOutlines(array $parts) {
  $number_parts = count($parts);
  $ancestors = array();
  $length = $number_parts - 1;
  $end = (1 << $number_parts) - 1;

  // The highest possible mask is a 1 bit for every part of the path. We will
  // check every value down from there to generate a possible outline.
  $masks = range($end, 0);

  // Only examine patterns that actually exist as router items (the masks).
  foreach ($masks as $i) {
    if ($i > $end) {

      // Only look at masks that are not longer than the path of interest.
      continue;
    }
    elseif ($i < 1 << $length) {

      // We have exhausted the masks of a given length, so decrease the length.
      --$length;
    }
    $current = '';
    for ($j = $length; $j >= 0; $j--) {

      // Check the bit on the $j offset.
      if ($i & 1 << $j) {

        // Bit one means the original value.
        $current .= $parts[$length - $j];
      }
      else {

        // Bit zero means means wildcard.
        $current .= '%';
      }

      // Unless we are at offset 0, add a slash.
      if ($j) {
        $current .= '/';
      }
    }
    $ancestors[] = '/' . $current;
  }
  return $ancestors;
}