Esempio n. 1
0
 /**
  * @inheritdoc
  *
  * @see \Spice\Routing\RouteInterface::match()
  */
 public function match(RequestInterface $request)
 {
     if ($request->getUri() === $this->getMatchPattern()) {
         return new \Spice\Routing\RouteMatch($this->getName(), $this->getDefaults());
     }
     throw new \Spice\Routing\RouteMismatchException("A rota {$this->getName()} não combina com a requisição.");
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  *
  * **Importante:** Em caso de sucesso na combinação com a requisição,
  * parâmetros padrão da requisição serão retornados 
  *
  * @see \Spice\Routing\RouteInterface::match()
  */
 public function match(RequestInterface $request)
 {
     $uri = $request->getUri();
     if (preg_match($this->getMatchRegex(), $uri, $matches)) {
         $paramMatches = $this->getDefaults() + array_filter($matches);
         foreach ($paramMatches as $key => $value) {
             if (is_numeric($key)) {
                 unset($paramMatches[$key]);
             }
         }
         return new RouteMatch($this->getName(), $paramMatches);
     }
     throw new RouteMismatchException(sprintf("A URI %s não casa com o padrão %s.", $uri, $this->getMatchPattern()));
 }