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\DumperCode
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>-><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;
}