You are here

public static function RouteCompiler::getFit in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Routing/RouteCompiler.php \Drupal\Core\Routing\RouteCompiler::getFit()
  2. 9 core/lib/Drupal/Core/Routing/RouteCompiler.php \Drupal\Core\Routing\RouteCompiler::getFit()

Determines the fitness of the provided path.

Parameters

string $path: The path whose fitness we want.

Return value

int The fitness of the path, as an integer.

File

core/lib/Drupal/Core/Routing/RouteCompiler.php, line 89

Class

RouteCompiler
Compiler to generate derived information from a Route necessary for matching.

Namespace

Drupal\Core\Routing

Code

public static function getFit($path) {
  $parts = explode('/', trim($path, '/'));
  $number_parts = count($parts);

  // We store the highest index of parts here to save some work in the fit
  // calculation loop.
  $slashes = $number_parts - 1;

  // The fit value is a binary number which has 1 at every fixed path
  // position and 0 where there is a wildcard. We keep track of all such
  // patterns that exist so that we can minimize the number of path
  // patterns we need to check in the RouteProvider.
  $fit = 0;
  foreach ($parts as $k => $part) {
    if (strpos($part, '{') === FALSE) {
      $fit |= 1 << $slashes - $k;
    }
  }
  return $fit;
}