Example #1
0
 /**
  * Add route
  *
  * @param  string[] $methods Array of HTTP methods
  * @param  string   $pattern The route pattern
  * @param  callable $handler The route callable
  *
  * @return RouteInterface
  *
  * @throws InvalidArgumentException if the route pattern isn't a string
  */
 public function map($methods, $pattern, $handler)
 {
     if (!is_string($pattern)) {
         throw new InvalidArgumentException('Route pattern must be a string');
     }
     // pattern must start with a / if not empty
     if ($pattern) {
         $pattern = '/' . ltrim($pattern, '/');
     }
     // Prepend parent group pattern(s)
     if ($this->routeGroups) {
         $pattern = $this->processGroups() . $pattern;
     }
     // Complete pattern must start with a /
     $pattern = '/' . ltrim($pattern, '/');
     // Add route
     $route = new Route($methods, $pattern, $handler, $this->routeGroups, $this->routeCounter);
     $this->routes[$route->getIdentifier()] = $route;
     $this->routeCounter++;
     return $route;
 }
 /**
  * Add route
  *
  * @param  string[] $methods Array of HTTP methods
  * @param  string   $pattern The route pattern
  * @param  callable $handler The route callable
  *
  * @return RouteInterface
  *
  * @throws InvalidArgumentException if the route pattern isn't a string
  */
 public function map($methods, $pattern, $handler)
 {
     if (!is_string($pattern)) {
         throw new InvalidArgumentException('Route pattern must be a string');
     }
     // Prepend parent group pattern(s)
     if ($this->routeGroups) {
         $pattern = $this->processGroups() . $pattern;
     }
     // According to RFC methods are defined in uppercase (See RFC 7231)
     $methods = array_map("strtoupper", $methods);
     // Add route
     $route = new Route($methods, $pattern, $handler, $this->routeGroups, $this->routeCounter);
     $this->routes[$route->getIdentifier()] = $route;
     $this->routeCounter++;
     return $route;
 }
 /**
  * Add route
  *
  * @param  string[] $methods Array of HTTP methods
  * @param  string   $pattern The route pattern
  * @param  callable $handler The route callable
  *
  * @return RouteInterface
  *
  * @throws InvalidArgumentException if the route pattern isn't a string
  */
 public function map($methods, $pattern, $handler)
 {
     if (!is_string($pattern)) {
         throw new InvalidArgumentException('Route pattern must be a string');
     }
     // Prepend parent group pattern(s)
     if ($this->routeGroups) {
         // If any route in the group only has / we remove it
         if ($pattern === '/') {
             $pattern = '';
         }
         $pattern = $this->processGroups() . $pattern;
     }
     // Add route
     $route = new Route($methods, $pattern, $handler, $this->routeGroups, $this->routeCounter);
     $this->routes[$route->getIdentifier()] = $route;
     $this->routeCounter++;
     return $route;
 }