You are here

public static function RouteCompiler::getFit in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Routing/RouteCompiler.php \Drupal\Core\Routing\RouteCompiler::getFit()
  2. 10 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.

1 call to RouteCompiler::getFit()
RouteCompiler::compile in core/lib/Drupal/Core/Routing/RouteCompiler.php
Compiles the current route instance.

File

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

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