private function PhpMatcherDumper::compileRoutes

Generates PHP code to match a RouteCollection with all its routes.

Parameters

RouteCollection $routes A RouteCollection instance:

Boolean $supportsRedirections Whether redirections are supported by the base class:

Return value

string PHP code

1 call to PhpMatcherDumper::compileRoutes()
PhpMatcherDumper::generateMatchMethod in drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
Generates the code for the match method implementing UrlMatcherInterface.

File

drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php, line 110

Class

PhpMatcherDumper
PhpMatcherDumper creates a PHP class able to match URLs for a given set of routes.

Namespace

Symfony\Component\Routing\Matcher\Dumper

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