Пример #1
0
 /**
  * @inheritdoc
  * @param array $matches The list of regex matches
  */
 public function isMatch(ParsedRoute $route, Request $request, array &$matches = [])
 {
     $isMatch = preg_match($route->getHostRegex(), $request->getHeaders()->get("HOST"), $matches) === 1;
     // Remove the subject
     array_shift($matches);
     return $isMatch;
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function isMatch(ParsedRoute $route, Request $request)
 {
     return $route->isSecure() && $request->isSecure() || !$route->isSecure();
 }
Пример #3
0
 /**
  * Adds a route to the collection
  *
  * @param ParsedRoute $route The route to add
  */
 public function add(ParsedRoute $route)
 {
     foreach ($route->getMethods() as $method) {
         $this->routes[$method][] = $route;
         if (!empty($route->getName())) {
             $this->namedRoutes[$route->getName()] =& $route;
         }
     }
 }
Пример #4
0
 /**
  * Generates the path portion of a URL for a route
  *
  * @param ParsedRoute $route The route whose URL we're generating
  * @param mixed|array $values The value or list of values to fill the route with
  * @return string The generated path value
  * @throws URLException Thrown if the generated path is not valid
  */
 private function generatePath(ParsedRoute $route, &$values)
 {
     return $this->generateUrlPart($route->getRawPath(), $route->getPathRegex(), $route->getName(), $values);
 }
Пример #5
0
 /**
  * Parses a variable and returns the regex
  *
  * @param ParsedRoute $parsedRoute The route being parsed
  * @param string $segment The segment being parsed
  * @return string The variable regex
  * @throws RouteException Thrown if the variable definition is invalid
  */
 private function getVarRegex(ParsedRoute $parsedRoute, $segment)
 {
     preg_match(self::$variableMatchingRegex, $segment, $matches);
     $variableName = $matches[1];
     $defaultValue = isset($matches[2]) ? $matches[2] : "";
     if (in_array($variableName, $this->variableNames)) {
         throw new RouteException("Route uses multiple references to \"{$variableName}\"");
     }
     $this->variableNames[] = $variableName;
     $parsedRoute->setDefaultValue($variableName, $defaultValue);
     $variableRegex = $parsedRoute->getVarRegex($variableName);
     if ($variableRegex === null) {
         // Add a default regex
         $variableRegex = "[^\\/:]+";
     }
     $this->cursor += mb_strlen($matches[0]);
     return sprintf("(?P<%s>%s)", $variableName, $variableRegex);
 }