/**
  * @inheritDoc
  */
 public function match(PsrRequest $request)
 {
     // Must inject routes prior to matching.
     $this->injectRoutes();
     $match = $this->zendRouter->match(Psr7ServerRequest::toZend($request, true));
     if (null === $match) {
         return RouteResult::fromRouteFailure();
     }
     return $this->marshalSuccessResultFromRouteMatch($match);
 }
Beispiel #2
0
 /**
  * Attempt to match an incoming request to a registered route.
  *
  * @param PsrRequest $request
  * @return RouteResult
  */
 public function match(PsrRequest $request)
 {
     $match = $this->zf2Router->match(Psr7ServerRequest::toZend($request, true));
     if (null === $match) {
         return RouteResult::fromRouteFailure();
     }
     $allowedMethods = $this->getAllowedMethods($match->getMatchedRouteName());
     if (!$this->methodIsAllowed($request->getMethod(), $allowedMethods)) {
         return RouteResult::fromRouteFailure($allowedMethods);
     }
     return $this->marshalSuccessResultFromRouteMatch($match);
 }
Beispiel #3
0
 /**
  * Attempt to match an incoming request to a registered route.
  *
  * @param PsrRequest $request
  * @return RouteResult
  */
 public function match(PsrRequest $request)
 {
     $match = $this->zf2Router->match(Psr7ServerRequest::toZend($request, true));
     if (null === $match) {
         return RouteResult::fromRouteFailure();
     }
     return $this->marshalSuccessResultFromRouteMatch($match);
 }
 /**
  * match(): defined by \Zend\Mvc\Router\RouteInterface
  *
  * @see    \Zend\Mvc\Router\RouteInterface::match()
  * @param  Request      $request
  * @param  integer|null $pathOffset
  * @param  array        $options
  * @return RouteMatch|null
  */
 public function match(Request $request, $pathOffset = null, array $options = array())
 {
     if ($this->hasTranslator() && $this->isTranslatorEnabled() && !isset($options['translator'])) {
         $options['translator'] = $this->getTranslator();
     }
     if (!isset($options['text_domain'])) {
         $options['text_domain'] = $this->getTranslatorTextDomain();
     }
     return parent::match($request, $pathOffset, $options);
 }
 private function matchUrl($url, $urlHelper)
 {
     $url = 'http://localhost.localdomain' . $url;
     $request = new Request();
     $request->setUri($url);
     $router = new TreeRouteStack();
     $router->addRoute('hostname', ['type' => 'hostname', 'options' => ['route' => 'localhost.localdomain'], 'child_routes' => ['resource' => ['type' => 'segment', 'options' => ['route' => '/resource[/:id]']]]]);
     $match = $router->match($request);
     if ($match instanceof RouteMatch) {
         $urlHelper->setRouter($router);
         $urlHelper->setRouteMatch($match);
     }
     return $match;
 }
 public function setUpRouter()
 {
     if (isset($this->router)) {
         return;
     }
     $this->setUpRequest();
     $routes = ['resource' => ['type' => 'Segment', 'options' => ['route' => '/api/resource[/:id]', 'defaults' => ['controller' => 'Api\\RestController']]]];
     $this->router = $router = new TreeRouteStack();
     $router->addRoutes($routes);
     $matches = $router->match($this->request);
     if (!$matches instanceof RouteMatch) {
         $this->fail('Failed to route!');
     }
     $this->matches = $matches;
 }
 public function testDefaultParamDoesNotOverrideParam()
 {
     $stack = new TreeRouteStack();
     $stack->setBaseUrl('/foo');
     $stack->addRoute('foo', new TestAsset\DummyRouteWithParam());
     $stack->setDefaultParam('foo', 'baz');
     $this->assertEquals('bar', $stack->match(new Request())->getParam('foo'));
 }