getFit example


  public function testGetFit($path$expected) {
    $route_compiler = new RouteCompiler();
    $result = $route_compiler->getFit($path);
    $this->assertSame($expected$result);
  }

  /** * Provides data for RouteCompilerTest::testGetFit() * * @return array * An array of arrays, where each inner array has the path whose fit is to * be calculated as the first value and the expected fit as the second * value. */
  

  protected function applyFitOrder(RouteCollection $collection) {
    $buckets = [];
    // Sort all the routes by fit descending.     foreach ($collection->all() as $name => $route) {
      $fit = $route->compile()->getFit();
      $buckets += [$fit => []];
      $buckets[$fit][] = [$name$route];
    }
    krsort($buckets);

    $flattened = array_reduce($buckets, 'array_merge', []);

    // Add them back onto a new route collection.     $collection = new RouteCollection();
    foreach ($flattened as $pair) {
      $name = $pair[0];
      

        $names = [];
        foreach ($routes as $name => $route) {
          /** @var \Symfony\Component\Routing\Route $route */
          $route->setOption('compiler_class', RouteCompiler::class);
          /** @var \Drupal\Core\Routing\CompiledRoute $compiled */
          $compiled = $route->compile();
          // 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.           $masks[$compiled->getFit()] = 1;
          $names[] = $name;
          $values = [
            'name' => $name,
            'fit' => $compiled->getFit(),
            'path' => $route->getPath(),
            'pattern_outline' => $compiled->getPatternOutline(),
            'number_parts' => $compiled->getNumParts(),
            'route' => serialize($route),
          ];
          $insert->values($values);
        }

        

  public static function compile(Route $route): CompiledRoute {
    // Symfony 4 requires that all UTF-8 route patterns have the "utf8" option     // set and Drupal does not support non UTF-8 routes.     $route->setOption('utf8', TRUE);
    $symfony_compiled = parent::compile($route);

    // The Drupal-specific compiled information.     $stripped_path = static::getPathWithoutDefaults($route);
    $fit = static::getFit($stripped_path);
    $pattern_outline = static::getPatternOutline($stripped_path);
    // We count the number of parts including any optional trailing parts. This     // allows the RouteProvider to filter candidate routes more efficiently.     $num_parts = count(explode('/', trim($route->getPath(), '/')));

    return new CompiledRoute(
      $fit,
      $pattern_outline,
      $num_parts,

      // The following parameters are what Symfony uses in
Home | Imprint | This part of the site doesn't use cookies.