Generates PHP code to match a RouteCollection with all its routes.
RouteCollection $routes A RouteCollection instance:
Boolean $supportsRedirections Whether redirections are supported by the base class:
string PHP code
private function compileRoutes(RouteCollection $routes, $supportsRedirections) {
$fetchedHost = false;
$groups = $this
->groupRoutesByHostRegex($routes);
$code = '';
foreach ($groups as $collection) {
if (null !== ($regex = $collection
->getAttribute('host_regex'))) {
if (!$fetchedHost) {
$code .= " \$host = \$this->context->getHost();\n\n";
$fetchedHost = true;
}
$code .= sprintf(" if (preg_match(%s, \$host, \$hostMatches)) {\n", var_export($regex, true));
}
$tree = $this
->buildPrefixTree($collection);
$groupCode = $this
->compilePrefixRoutes($tree, $supportsRedirections);
if (null !== $regex) {
// apply extra indention at each line (except empty ones)
$groupCode = preg_replace('/^.{2,}$/m', ' $0', $groupCode);
$code .= $groupCode;
$code .= " }\n\n";
}
else {
$code .= $groupCode;
}
}
return $code;
}