/**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable|null $next
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) : ResponseInterface
 {
     $result = $this->router->match($request);
     $request = $this->applyRoutingResult($request, $result);
     if ($next) {
         $response = $next($request->withAttribute($this->routingResultAttribute, $result), $response);
     }
     return $response;
 }
 /**
  * @test
  */
 public function requestContainsRoutingResultInRoutingResultAttributeAfterRouting()
 {
     $self = $this;
     $route = RouteBuilder::route()->get('/test')->to('testAction')->build();
     $routingResult = RoutingResult::forSuccess($route);
     $this->router->expects($this->any())->method('match')->will($this->returnValue($routingResult));
     $next = function ($request, $response) use($routingResult, $self) {
         $self->assertSame($routingResult, $request->getAttribute(RoutingResult::class));
         return $response;
     };
     $this->middleware->__invoke($this->request, $this->response, $next);
 }
Example #3
0
 /**
  * Adds given route to router
  *
  * @param Route $route
  * @throws \InvalidArgumentException
  * @return Adrenaline
  */
 public function addRoute(Route $route) : self
 {
     $this->router->addRoute($route);
     return $this;
 }