public function PathMatcher::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 PathMatcher::getCandidateOutlines()
PathMatcher::matchRequestPartial in drupal/core/lib/Drupal/Core/Routing/PathMatcher.php
Matches a request against multiple routes.

File

drupal/core/lib/Drupal/Core/Routing/PathMatcher.php, line 108
Definition of Drupal\Core\Routing\PathMatcher.

Class

PathMatcher
Initial matcher to match a route against a built database, by path.

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, pow($number_parts - 1, 2));

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