Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RouteCompiler.php

function RouteCompiler::compile

Same name in this branch
  1. 11.1.x vendor/symfony/routing/RouteCompiler.php \Symfony\Component\Routing\RouteCompiler::compile()

Compiles the current route instance.

Because so much of the parent class is private, we need to call the parent class's compile() method and then dissect its return value to build our new compiled object. If upstream gets refactored so we can subclass more easily then this may not be necessary.

Parameters

\Symfony\Component\Routing\Route $route: A Route instance.

Return value

\Drupal\Core\Routing\CompiledRoute A CompiledRoute instance.

Overrides RouteCompiler::compile

File

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

Class

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

Namespace

Drupal\Core\Routing

Code

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, '', $symfony_compiled->getRegex(), $symfony_compiled->getTokens(), $symfony_compiled->getPathVariables(), $symfony_compiled->getHostRegex(), $symfony_compiled->getHostTokens(), $symfony_compiled->getHostVariables(), $symfony_compiled->getVariables());
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal