You are here

private function PhpMatcherDumper::compileRoutes in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/routing/Matcher/Dumper/PhpMatcherDumper.php \Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper::compileRoutes()

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

Parameters

RouteCollection $routes A RouteCollection instance:

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

Return value

string PHP code

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

File

vendor/symfony/routing/Matcher/Dumper/PhpMatcherDumper.php, line 126

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