예제 #1
0
 /**
  * Builds URI for provided route instance.
  *
  * @param RouteContract $route
  * @param array $variables
  * @param array $query
  * @return UriInterface
  */
 private function buildRouteUri(RouteContract $route, array $variables = [], array $query = []) : UriInterface
 {
     $uri = $this->uri->withScheme($route->getScheme() ?: $this->request->getUri()->getScheme())->withHost($route->getHost() ?: $this->request->getUri()->getHost())->withPath($route->compilePath($variables));
     if ($query) {
         $uri = $uri->withQuery(http_build_query($query));
     }
     return $uri;
 }
예제 #2
0
 function it_parses_routes(RouteCollector $collector, Route $route)
 {
     $route->getMethods()->willReturn(['GET']);
     $route->getPath()->willReturn('/url');
     $collector->addRoute(['GET'], '/url', $route)->shouldBeCalled();
     $collector->getData()->willReturn(['parse result']);
     $this->parse([$route])->shouldBe(['parse result']);
 }
예제 #3
0
 function it_calls_responder_only_when_domain_is_not_callable(Container $container, Route $route, Request $request, Response $response, Responder $responder)
 {
     $route->getDomain()->willReturn('');
     $route->getResponder()->willReturn(Responder::class);
     $container->isCallable('')->willReturn(false);
     $container->get(Responder::class)->willReturn($responder);
     $responder->run($request, null)->willReturn($response);
     $this->next($request)->shouldBe($response);
 }
예제 #4
0
 /**
  * @inheritDoc
  */
 public function next(ServerRequestInterface $request) : ResponseInterface
 {
     if (!$request instanceof RequestContract) {
         // Decorate PSR-7 ServerRequest.
         $request = new Request($request);
     }
     if ($this->container->isCallable($this->route->getDomain())) {
         if ($this->container->has($this->route->getInput())) {
             /** @var Input $input */
             $input = $this->container->get($this->route->getInput());
             $arguments = $input->process($request);
         }
         /** @var Payload $payload */
         $payload = $this->container->call($this->route->getDomain(), $arguments ?? []);
     }
     /** @var Responder $responder */
     $responder = $this->container->get($this->route->getResponder());
     return $responder->run($request, $payload ?? null);
 }
예제 #5
0
 function let(RouteParser $parser, FastrouteDispatcherFactory $factory, Route $route, Dispatcher $dispatcher)
 {
     $parser->parse(Argument::containing($route->getWrappedObject()))->willReturn(['parsed']);
     $factory->create(['parsed'])->willReturn($dispatcher);
     $this->beConstructedWith($parser, $factory);
 }