Example #1
0
 /**
  * Adding Route in collection
  *
  * @param Route $route
  * @return $this
  */
 public function add(Route $route)
 {
     $route->setParser($this->parser);
     $hash = sha1($route->getMethod() . $route->getUrl());
     if (isset($this->allRoutes[$hash])) {
         throw new \InvalidArgumentException('Duplicate route url ' . $route->getMethod() . ' ' . $route->getUrl());
     }
     $this->allRoutes[$hash] = $route;
     if ($route->hasName()) {
         if (isset($this->namedRoutes[$route->getName()])) {
             throw new \InvalidArgumentException('Duplicate route name ' . $route->getName());
         }
         $this->namedRoutes[$route->getName()] = $route;
     }
     if (!$route->hasRegex()) {
         if (isset($this->literalRoutes[$this->getLiteralRouteKey($route->getUrl(), $route->getMethod())])) {
             throw new \InvalidArgumentException('Duplicate route url ' . $route->getUrl());
         }
         $this->literalRoutes[$route->getMethod() . ' ' . $route->getUrl()] = $route;
     } else {
         $this->regexRoutes[$route->getStaticPrefix()][$route->getMethod()][] = $route;
     }
     return $this;
 }