*/ class ResponseEmitter { /** * Emit a Http Response to client * * @see https://github.com/http-interop/response-sender * @param ResponseInterface $response */ public function __invoke(ResponseInterface $response) { $http_line = sprintf( 'HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase() ); if (!headers_sent()) { header($http_line, true, $response->getStatusCode()); foreach ($response->getHeaders() as $name => $values) { foreach ($values as $value) { header("$name: $value", false); } } } $stream = $response->getBody(); if ($stream->isSeekable()) { $stream->rewind(); } while (!$stream->eof()) { echo $stream->read(1024 * 8); } } }