/**
  * {@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 static function compile(Route $route)
 {
     $staticPrefix = null;
     $hostVariables = array();
     $pathVariables = array();
     $variables = array();
     $tokens = array();
     $regex = null;
     $hostRegex = null;
     $hostTokens = array();
     if ('' !== ($host = $route->getHost())) {
         $result = self::compilePattern($route, $host, true);
         $hostVariables = $result['variables'];
         $variables = array_merge($variables, $hostVariables);
         $hostTokens = $result['tokens'];
         $hostRegex = $result['regex'];
     }
     $path = $route->getPath();
     $result = self::compilePattern($route, $path, 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, $hostRegex, $hostTokens, $hostVariables, array_unique($variables));
 }
Example #2
0
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException If a path variable is named _fragment
  * @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 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));
 }