Example #1
0
 /**
  * {@inheritDoc}
  *
  * @throws \LogicException  If a variable is referenced more than once
  * @throws \DomainException If a variable name is numeric because PHP raises an error for such
  *                          subpatterns in PCRE and thus would break matching, e.g. "(?P<123>.+)".
  */
 public function compile(Route $route)
 {
     $staticPrefix = null;
     $hostnameVariables = array();
     $pathVariables = array();
     $variables = array();
     $tokens = array();
     $regex = null;
     $hostnameRegex = null;
     $hostnameTokens = array();
     if ('' !== ($hostnamePattern = $route->getHostnamePattern())) {
         $result = $this->compilePattern($route, $hostnamePattern, true);
         $hostnameVariables = $result['variables'];
         $variables = array_merge($variables, $hostnameVariables);
         $hostnameTokens = $result['tokens'];
         $hostnameRegex = $result['regex'];
     }
     $pattern = $route->getPattern();
     $result = $this->compilePattern($route, $pattern, false);
     $staticPrefix = $result['staticPrefix'];
     $pathVariables = $result['variables'];
     $variables = array_merge($variables, $pathVariables);
     $tokens = $result['tokens'];
     $regex = $result['regex'];
     return new CompiledRoute($staticPrefix, $regex, $tokens, $pathVariables, $hostnameRegex, $hostnameTokens, $hostnameVariables, array_unique($variables));
 }