Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }