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

Breadcrumb

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

function CompiledUrlMatcherDumper::getCompiledRoutes

Generates the arrays for CompiledUrlMatcher's constructor.

1 call to CompiledUrlMatcherDumper::getCompiledRoutes()
CompiledUrlMatcherDumper::generateCompiledRoutes in vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherDumper.php

File

vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherDumper.php, line 61

Class

CompiledUrlMatcherDumper
CompiledUrlMatcherDumper creates PHP arrays to be used with CompiledUrlMatcher.

Namespace

Symfony\Component\Routing\Matcher\Dumper

Code

public function getCompiledRoutes(bool $forDump = false) : array {
    // Group hosts by same-suffix, re-order when possible
    $matchHost = false;
    $routes = new StaticPrefixCollection();
    foreach ($this->getRoutes()
        ->all() as $name => $route) {
        if ($host = $route->getHost()) {
            $matchHost = true;
            $host = '/' . strtr(strrev($host), '}.{', '(/)');
        }
        $routes->addRoute($host ?: '/(.*)', [
            $name,
            $route,
        ]);
    }
    if ($matchHost) {
        $compiledRoutes = [
            true,
        ];
        $routes = $routes->populateCollection(new RouteCollection());
    }
    else {
        $compiledRoutes = [
            false,
        ];
        $routes = $this->getRoutes();
    }
    [
        $staticRoutes,
        $dynamicRoutes,
    ] = $this->groupStaticRoutes($routes);
    $conditions = [
        null,
    ];
    $compiledRoutes[] = $this->compileStaticRoutes($staticRoutes, $conditions);
    $chunkLimit = \count($dynamicRoutes);
    while (true) {
        try {
            $this->signalingException = new \RuntimeException('Compilation failed: regular expression is too large');
            $compiledRoutes = array_merge($compiledRoutes, $this->compileDynamicRoutes($dynamicRoutes, $matchHost, $chunkLimit, $conditions));
            break;
        } catch (\Exception $e) {
            if (1 < $chunkLimit && $this->signalingException === $e) {
                $chunkLimit = 1 + ($chunkLimit >> 1);
                continue;
            }
            throw $e;
        }
    }
    if ($forDump) {
        $compiledRoutes[2] = $compiledRoutes[4];
    }
    unset($conditions[0]);
    if ($conditions) {
        foreach ($conditions as $expression => $condition) {
            $conditions[$expression] = "case {$condition}: return {$expression};";
        }
        $checkConditionCode = <<<EOF
    static function (\$condition, \$context, \$request, \$params) { // \$checkCondition
        switch (\$condition) {
{<span class="php-variable">$this</span>-&gt;<span class="php-function-or-constant function member-of-self">indent</span>(<span class="php-function-or-constant">implode</span>(<span class="php-string">"\n"</span>, <span class="php-variable">$conditions</span>), <span class="php-constant">3</span>)}
        }
    }
EOF;
        $compiledRoutes[4] = $forDump ? $checkConditionCode . ",\n" : eval('return ' . $checkConditionCode . ';');
    }
    else {
        $compiledRoutes[4] = $forDump ? "    null, // \$checkCondition\n" : null;
    }
    return $compiledRoutes;
}

API Navigation

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