getPatternOutline example


  protected function overrideAppliesPathAndMethod($view_path, Route $view_route, Route $route) {
    // Find all paths which match the path of the current display..     $route_path = RouteCompiler::getPathWithoutDefaults($route);
    $route_path = RouteCompiler::getPatternOutline($route_path);

    // Ensure that we don't override a route which is already controlled by     // views.     return !$route->hasDefault('view_id')
    && ('/' . $view_path == $route_path)
    // Also ensure that we don't override for example REST routes.     && (!$route->getMethods() || in_array('GET', $route->getMethods()));
  }

  /** * {@inheritdoc} */
$dumper->addRoutes($this->fixtures->complexRouteCollection());
    $dumper->dump();

    $path = '/path/1/one';

    $request = Request::create($path, 'GET');

    $routes = $provider->getRouteCollectionForRequest($request);

    // All of the matching paths have the correct pattern.     foreach ($routes as $route) {
      $this->assertEquals('/path/%/one', $route->compile()->getPatternOutline(), 'Found path has correct pattern');
    }

    $this->assertCount(2, $routes, 'The correct number of routes was found.');
    $this->assertNotNull($routes->get('route_a'), 'The first matching route was found.');
    $this->assertNotNull($routes->get('route_b'), 'The second matching route was not found.');
  }

  /** * Data provider for testMixedCasePaths() */
  public function providerMixedCaseRoutePaths() {
    


  /** * Confirms that a route compiles properly with the necessary data. */
  public function testCompilation() {
    $route = new Route('/test/{something}/more');
    $route->setOption('compiler_class', RouteCompiler::class);
    $compiled = $route->compile();

    $this->assertEquals(5 /* That's 101 binary*/, $compiled->getFit(), 'The fit was incorrect.');
    $this->assertEquals('/test/%/more', $compiled->getPatternOutline(), 'The pattern outline was not correct.');
  }

  /** * Confirms that a compiled route with default values has the correct outline. */
  public function testCompilationDefaultValue() {
    // Because "here" has a default value, it should not factor into the outline     // or the fitness.     $route = new Route('/test/{something}/more/{here}', [
      'here' => 'there',
    ]);
    

      }
      $ancestors[] = '/' . $current;
    }
    return $ancestors;
  }

  /** * {@inheritdoc} */
  public function getRoutesByPattern($pattern) {
    $path = RouteCompiler::getPatternOutline($pattern);

    return $this->getRoutesByPath($path);
  }

  /** * Get all routes which match a certain pattern. * * @param string $path * The route pattern to search for. * * @return \Symfony\Component\Routing\RouteCollection * Returns a route collection of matching routes. The collection may be * empty and will be sorted from highest to lowest fit (match of path parts) * and then in ascending order by route name for routes with the same fit. */
$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);
        }

        // Insert all new routes.         $insert->execute();
      }

    }
    

  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       // \Symfony\Component\Routing\Matcher\UrlMatcher::matchCollection().
Home | Imprint | This part of the site doesn't use cookies.