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

Breadcrumb

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

function CompiledUrlMatcherDumper::compileStaticPrefixCollection

Compiles a regexp tree of subpatterns that matches nested same-prefix routes.

Parameters

\stdClass $state A simple state object that keeps track of the progress of the compilation,: and gathers the generated switch's "case" and "default" statements

1 call to CompiledUrlMatcherDumper::compileStaticPrefixCollection()
CompiledUrlMatcherDumper::compileDynamicRoutes in vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherDumper.php
Compiles a regular expression followed by a switch statement to match dynamic routes.

File

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

Class

CompiledUrlMatcherDumper
CompiledUrlMatcherDumper creates PHP arrays to be used with CompiledUrlMatcher.

Namespace

Symfony\Component\Routing\Matcher\Dumper

Code

private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \stdClass $state, int $prefixLen, array &$conditions) : string {
    $code = '';
    $prevRegex = null;
    $routes = $tree->getRoutes();
    foreach ($routes as $i => $route) {
        if ($route instanceof StaticPrefixCollection) {
            $prevRegex = null;
            $prefix = substr($route->getPrefix(), $prefixLen);
            $state->mark += \strlen($rx = "|{$prefix}(?");
            $code .= "\n            ." . self::export($rx);
            $state->regex .= $rx;
            $code .= $this->indent($this->compileStaticPrefixCollection($route, $state, $prefixLen + \strlen($prefix), $conditions));
            $code .= "\n            .')'";
            $state->regex .= ')';
            ++$state->markTail;
            continue;
        }
        [
            $name,
            $regex,
            $vars,
            $route,
            $hasTrailingSlash,
            $hasTrailingVar,
        ] = $route;
        $compiledRoute = $route->compile();
        $vars = array_merge($state->hostVars, $vars);
        if ($compiledRoute->getRegex() === $prevRegex) {
            $state->routes[$state->mark][] = $this->compileRoute($route, $name, $vars, $hasTrailingSlash, $hasTrailingVar, $conditions);
            continue;
        }
        $state->mark += 3 + $state->markTail + \strlen($regex) - $prefixLen;
        $state->markTail = 2 + \strlen($state->mark);
        $rx = \sprintf('|%s(*:%s)', substr($regex, $prefixLen), $state->mark);
        $code .= "\n            ." . self::export($rx);
        $state->regex .= $rx;
        $prevRegex = $compiledRoute->getRegex();
        $state->routes[$state->mark] = [
            $this->compileRoute($route, $name, $vars, $hasTrailingSlash, $hasTrailingVar, $conditions),
        ];
    }
    return $code;
}

API Navigation

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