function RouteCompiler::getFit
Same name in other branches
- 9 core/lib/Drupal/Core/Routing/RouteCompiler.php \Drupal\Core\Routing\RouteCompiler::getFit()
- 8.9.x core/lib/Drupal/Core/Routing/RouteCompiler.php \Drupal\Core\Routing\RouteCompiler::getFit()
- 11.x 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 89
Class
- RouteCompiler
- Compiler to generate derived information from a Route necessary for matching.
Namespace
Drupal\Core\RoutingCode
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 (!str_contains($part, '{')) {
$fit |= 1 << $slashes - $k;
}
}
return $fit;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.