Example #1
0
 public function add(Route $route)
 {
     $path = $route->getParsed()->getPathPattern();
     $method = $route->getMethod();
     if (!isset($this->pathMethodMap[$path])) {
         $this->pathMethodMap[$path] = [];
     } else {
         if (in_array($method, $this->pathMethodMap[$path])) {
             throw new \InvalidArgumentException("Method {$method} is already defined for {$path}");
         }
     }
     $name = $route->getName();
     if ($name !== null) {
         if (isset($this->routeNames[$name])) {
             throw new \InvalidArgumentException("Route {$name} is already defined");
         }
         $this->routeNames[$name] = $route;
     }
     $this->pathMethodMap[$path][] = $method;
     $this->routes[] = $route;
 }