Exemplo n.º 1
0
 public function testDispatchWithResolver()
 {
     $container = new Container();
     $container->set('first', function () {
         return function ($req, $res, $next) {
             $res->getBody()->write('1');
             return $next($req, $res);
         };
     });
     $container->set('second', function () {
         return function ($req, $res, $next) {
             $res->getBody()->write('2');
             return $next($req, $res);
         };
     });
     $middleware = ['first', 'second', function ($req, $res, $next) {
         return $next($req, $res);
     }];
     $resolver = new ContainerResolver($container);
     $dispatcher = new Dispatcher($middleware, $resolver);
     $response = $dispatcher->dispatch(ServerRequestFactory::fromGlobals(), new Response());
     $actual = (string) $response->getBody();
     $this->assertSame('12', $actual);
 }
Exemplo n.º 2
0
 /**
  * Dispatches the request and response through the registered middleware.
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request
  * @param  \Psr\Http\Message\ResponseInterface      $response
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 private function dispatchThroughMiddleware(ServerRequestInterface $request, ResponseInterface $response)
 {
     $dispatcher = new Dispatcher($this->middleware, new ContainerResolver($this->getContainer()));
     return $dispatcher->dispatch($request, $response);
 }