3 * Zend Framework (http://framework.zend.com/)
5 * @see http://github.com/zendframework/zend-diactoros for the canonical source repository
6 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
10 namespace Zend\Diactoros\Response;
12 use Psr\Http\Message\ResponseInterface;
15 class SapiEmitter implements EmitterInterface
20 * Emits a response for a PHP SAPI environment.
22 * Emits the status line and headers via the header() function, and the
23 * body content via the output buffer.
25 * @param ResponseInterface $response
26 * @param null|int $maxBufferLevel Maximum output buffering level to unwrap.
28 public function emit(ResponseInterface $response, $maxBufferLevel = null)
31 throw new RuntimeException('Unable to emit response; headers already sent');
34 $response = $this->injectContentLength($response);
36 $this->emitStatusLine($response);
37 $this->emitHeaders($response);
38 $this->flush($maxBufferLevel);
39 $this->emitBody($response);
43 * Emit the message body.
45 * @param ResponseInterface $response
47 private function emitBody(ResponseInterface $response)
49 echo $response->getBody();