You are here

private function PhpMatcherDumper::compilePrefixRoutes 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::compilePrefixRoutes()

Generates PHP code recursively to match a tree of routes.

Parameters

DumperPrefixCollection $collection A DumperPrefixCollection instance:

bool $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()
PhpMatcherDumper::compileRoutes in vendor/symfony/routing/Matcher/Dumper/PhpMatcherDumper.php
Generates PHP code to match a RouteCollection with all its routes.

File

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

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