/** * 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; }
/** * Returns the requested path * * @param RouteDefinition $route * @param Request $request * @return string */ protected function getRequestedPath(RouteDefinition $route, Request $request) { $pattern = rtrim($route->getPattern(), '/*'); $regex = RouteDefinitionCreator::createRegex($pattern, false); $path = preg_replace($regex, '', $request->getRequestedPath()); if (substr($path, 0, 1) != '/') { $path = '/' . $path; } if ($path != '/') { $path = rtrim($path, '/'); } return $path; }