/** * Append a route for given pattern * * @param string $pattern * @param string $handler * * @throws InvalidArgumentException */ public function append($pattern, $handler) { if (isset($this->routes[$pattern])) { throw new InvalidArgumentException('Pattern already mapped'); } if (!$this->isValidHandler($handler)) { throw new InvalidArgumentException('You must pass a closure or a class that implements' . ' ' . static::ROUTE_INTERFACE . ' interface'); } $this->sorted = false; $this->routes[$pattern] = $this->definitionCreator->create($pattern, $handler); }
/** * Append a new filter * * @param string $pattern * @param boolean $before * @param string $handler * @param array $httpMethods * @throws InvalidArgumentException */ public function append($pattern, $before, $handler, array $httpMethods = null) { if (isset($this->filters[(int) $before])) { $filterChain = $this->filters[(int) $before]; } else { $filterChain = array(); } if (!$this->isValidHandler($handler)) { throw new InvalidArgumentException('You must pass a closure or a class that extends the ' . static::FILTER_CLASS . ' class'); } $filterChain[] = $this->definitionCreator->create($pattern, $handler, $httpMethods); $this->filters[(int) $before] = $filterChain; }