public static compile ( Symfony\Component\Routing\Route $route ) | ||
$route | Symfony\Component\Routing\Route |
public static function compile(Route $route)
{
$hostVariables = array();
$variables = array();
$hostRegex = null;
$hostTokens = array();
if ('' !== ($host = $route->getHost())) {
$result = self::compilePattern($route, $host, true);
$hostVariables = $result['variables'];
$variables = $hostVariables;
$hostTokens = $result['tokens'];
$hostRegex = $result['regex'];
}
$path = $route->getPath();
$result = self::compilePattern($route, $path, false);
$staticPrefix = $result['staticPrefix'];
$pathVariables = $result['variables'];
foreach ($pathVariables as $pathParam) {
if ('_fragment' === $pathParam) {
throw new \InvalidArgumentException(sprintf('Route pattern "%s" cannot contain "_fragment" as a path parameter.', $route->getPath()));
}
}
$variables = array_merge($variables, $pathVariables);
$tokens = $result['tokens'];
$regex = $result['regex'];
return new CompiledRoute($staticPrefix, $regex, $tokens, $pathVariables, $hostRegex, $hostTokens, $hostVariables, array_unique($variables));
}
/** * Compiles the current route instance. * * Because so much of the parent class is private, we need to call the parent * class's compile() method and then dissect its return value to build our * new compiled object. If upstream gets refactored so we can subclass more * easily then this may not be necessary. * * @param \Symfony\Component\Routing\Route $route * A Route instance. * * @return \Drupal\Core\Routing\CompiledRoute * A CompiledRoute instance. */ public static function compile(Route $route) { $symfony_compiled = parent::compile($route); // The Drupal-specific compiled information. $stripped_path = static::getPathWithoutDefaults($route); $fit = static::getFit($stripped_path); $pattern_outline = static::getPatternOutline($stripped_path); $num_parts = count(explode('/', trim($pattern_outline, '/'))); return new CompiledRoute($route, $fit, $pattern_outline, $num_parts, $symfony_compiled->getStaticPrefix(), $symfony_compiled->getRegex(), $symfony_compiled->getTokens(), $symfony_compiled->getPathVariables(), $symfony_compiled->getHostRegex(), $symfony_compiled->getHostTokens(), $symfony_compiled->getHostVariables(), $symfony_compiled->getVariables()); }