setResponsePrototype() публичный Метод

public setResponsePrototype ( Psr\Http\Message\ResponseInterface $prototype ) : void
$prototype Psr\Http\Message\ResponseInterface
Результат void
Пример #1
0
 /**
  * @todo Remove the $done argument during setup for 2.0.0
  * @group http-interop
  */
 public function testProcessReturnsResponsePrototypeIfNoResponseReturnedByMiddleware()
 {
     $done = function ($req, $res, $err = null) {
         Assert::fail('Should not have hit the done handler, but did');
     };
     $request = $this->request->withUri(new Uri('http://example.com/foo/bar/baz'));
     $response = $this->prophesize(ResponseInterface::class)->reveal();
     $route1 = $this->prophesize(ServerMiddlewareInterface::class);
     $route1->process(Argument::that(function ($arg) {
         Assert::assertEquals('/bar/baz', $arg->getUri()->getPath());
         return true;
     }), Argument::type(Next::class))->willReturn('foobar');
     $this->queue->enqueue(new Route('/foo', $route1->reveal()));
     $route2 = $this->prophesize(ServerMiddlewareInterface::class);
     $route2->process(Argument::type(RequestInterface::class), Argument::type(Next::class))->shouldNotBeCalled();
     $this->queue->enqueue(new Route('/foo/bar', $route2->reveal()));
     $next = new Next($this->queue, $done);
     $next->setResponsePrototype($response);
     $this->assertSame($response, $next->process($request));
 }
 /**
  * http-interop invocation: single-pass with delegate.
  *
  * Executes the internal pipeline, passing $delegate as the "final
  * handler" in cases when the pipeline exhausts itself.
  *
  * @param Request $request
  * @param DelegateInterface $delegate
  * @return Response
  */
 public function process(Request $request, DelegateInterface $delegate)
 {
     $response = $this->responsePrototype;
     $next = new Next($this->pipeline, $delegate);
     if ($response) {
         $next->setResponsePrototype($response);
     }
     if ($this->raiseThrowables) {
         $next->raiseThrowables();
     }
     $result = $next->process($request);
     return $result instanceof Response ? $result : $response;
 }