private function PhpMatcherDumper::compilePrefixRoutes

Generates PHP code recursively to match a tree of routes

Parameters

DumperPrefixCollection $collection A DumperPrefixCollection instance:

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

string $parentPrefix Prefix of the parent collection:

Return value

string PHP code

1 call to PhpMatcherDumper::compilePrefixRoutes()

File

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

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 compilePrefixRoutes(DumperPrefixCollection $collection, $supportsRedirections, $parentPrefix = '') {
  $code = '';
  $prefix = $collection
    ->getPrefix();
  $optimizable = 1 < strlen($prefix) && 1 < count($collection
    ->all());
  $optimizedPrefix = $parentPrefix;
  if ($optimizable) {
    $optimizedPrefix = $prefix;
    $code .= sprintf("    if (0 === strpos(\$pathinfo, %s)) {\n", var_export($prefix, true));
  }
  foreach ($collection as $route) {
    if ($route instanceof DumperCollection) {
      $code .= $this
        ->compilePrefixRoutes($route, $supportsRedirections, $optimizedPrefix);
    }
    else {
      $code .= $this
        ->compileRoute($route
        ->getRoute(), $route
        ->getName(), $supportsRedirections, $optimizedPrefix) . "\n";
    }
  }
  if ($optimizable) {
    $code .= "    }\n\n";

    // apply extra indention at each line (except empty ones)
    $code = preg_replace('/^.{2,}$/m', '    $0', $code);
  }
  return $code;
}