Mercurial > hg > isophonics-drupal-site
annotate vendor/zendframework/zend-diactoros/src/Response/SapiEmitter.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 /** |
Chris@0 | 3 * Zend Framework (http://framework.zend.com/) |
Chris@0 | 4 * |
Chris@0 | 5 * @see http://github.com/zendframework/zend-diactoros for the canonical source repository |
Chris@0 | 6 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) |
Chris@0 | 7 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License |
Chris@0 | 8 */ |
Chris@0 | 9 |
Chris@0 | 10 namespace Zend\Diactoros\Response; |
Chris@0 | 11 |
Chris@0 | 12 use Psr\Http\Message\ResponseInterface; |
Chris@0 | 13 use RuntimeException; |
Chris@0 | 14 |
Chris@0 | 15 class SapiEmitter implements EmitterInterface |
Chris@0 | 16 { |
Chris@0 | 17 use SapiEmitterTrait; |
Chris@0 | 18 |
Chris@0 | 19 /** |
Chris@0 | 20 * Emits a response for a PHP SAPI environment. |
Chris@0 | 21 * |
Chris@0 | 22 * Emits the status line and headers via the header() function, and the |
Chris@0 | 23 * body content via the output buffer. |
Chris@0 | 24 * |
Chris@0 | 25 * @param ResponseInterface $response |
Chris@0 | 26 * @param null|int $maxBufferLevel Maximum output buffering level to unwrap. |
Chris@0 | 27 */ |
Chris@0 | 28 public function emit(ResponseInterface $response, $maxBufferLevel = null) |
Chris@0 | 29 { |
Chris@0 | 30 if (headers_sent()) { |
Chris@0 | 31 throw new RuntimeException('Unable to emit response; headers already sent'); |
Chris@0 | 32 } |
Chris@0 | 33 |
Chris@0 | 34 $response = $this->injectContentLength($response); |
Chris@0 | 35 |
Chris@0 | 36 $this->emitStatusLine($response); |
Chris@0 | 37 $this->emitHeaders($response); |
Chris@0 | 38 $this->flush($maxBufferLevel); |
Chris@0 | 39 $this->emitBody($response); |
Chris@0 | 40 } |
Chris@0 | 41 |
Chris@0 | 42 /** |
Chris@0 | 43 * Emit the message body. |
Chris@0 | 44 * |
Chris@0 | 45 * @param ResponseInterface $response |
Chris@0 | 46 */ |
Chris@0 | 47 private function emitBody(ResponseInterface $response) |
Chris@0 | 48 { |
Chris@0 | 49 echo $response->getBody(); |
Chris@0 | 50 } |
Chris@0 | 51 } |