Adds in write, end, and isComplete from RequestInterface in order to provide a common interface for all PSR HTTP implementations.
Inheritance: implements Psr\Http\Message\ResponseInterface, implements Zend\Stratigility\Http\ResponseInterface
Exemplo n.º 1
0
 /**
  * Middleware listener/
  *
  * @param          $class
  * @param Request  $request
  * @param Response $response
  *
  * @internal param Context $context
  */
 function middlewareSnooper($class, $request, $response)
 {
     static $count = 0;
     $this->kernel->context()->set('application.spy_middleware.fired', ++$count);
     $this->kernel->context()->set('application.spy_middleware.request_query', $request->getUri());
     $et = elapsed_time_since_request();
     $class = (new \ReflectionClass($class))->getShortName();
     $response->getBody()->write("<div><b>{$class}</b> middleware event fired @<b>{$et}</b></div>" . PHP_EOL);
 }
 /**
  * Write the given message to the response and mark it complete.
  *
  * If the message is an Http\Response decorator, call and return its
  * `end()` method; otherwise, decorate the response and `end()` it.
  *
  * @param ResponseInterface $response
  * @param string $message
  * @return Http\Response
  */
 private function completeResponse(ResponseInterface $response, $message)
 {
     if ($response instanceof Http\Response) {
         return $response->end($message);
     }
     $response = new Http\Response($response);
     return $response->end($message);
 }
 public function testCanReplaceOriginalResponseAndBodySizeAfterConstruction()
 {
     $psrResponse = new PsrResponse();
     $originalResponse = new Response(new PsrResponse());
     $originalResponse->write('foo');
     $final = new FinalHandler([], $psrResponse);
     $final->setOriginalResponse($originalResponse);
     /** @var Response $actualResponse */
     $actualResponse = self::readAttribute($final, 'response');
     $this->assertSame($originalResponse, $actualResponse);
     $this->assertSame(3, $actualResponse->getBody()->getSize());
 }
Exemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function withStatus($header, $reasonPhrase = null)
 {
     return new self($this->app, parent::withStatus($header, $reasonPhrase));
 }
 /**
  * @group 12
  */
 public function testReturnsResponseIfBodyLengthHasChanged()
 {
     $psrResponse = new PsrResponse();
     $response = new Response($psrResponse);
     $final = new FinalHandler([], $response);
     $response->write('return this response');
     $result = $final(new Request(new PsrRequest()), $response);
     $this->assertSame($response, $result);
 }