Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 /** | |
3 * Zend Framework (http://framework.zend.com/) | |
4 * | |
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 | |
8 */ | |
9 | |
10 namespace Zend\Diactoros\Response; | |
11 | |
12 use Psr\Http\Message\ResponseInterface; | |
13 use RuntimeException; | |
14 | |
15 class SapiEmitter implements EmitterInterface | |
16 { | |
17 use SapiEmitterTrait; | |
18 | |
19 /** | |
20 * Emits a response for a PHP SAPI environment. | |
21 * | |
22 * Emits the status line and headers via the header() function, and the | |
23 * body content via the output buffer. | |
24 * | |
25 * @param ResponseInterface $response | |
26 * @param null|int $maxBufferLevel Maximum output buffering level to unwrap. | |
27 */ | |
28 public function emit(ResponseInterface $response, $maxBufferLevel = null) | |
29 { | |
30 if (headers_sent()) { | |
31 throw new RuntimeException('Unable to emit response; headers already sent'); | |
32 } | |
33 | |
34 $response = $this->injectContentLength($response); | |
35 | |
36 $this->emitStatusLine($response); | |
37 $this->emitHeaders($response); | |
38 $this->flush($maxBufferLevel); | |
39 $this->emitBody($response); | |
40 } | |
41 | |
42 /** | |
43 * Emit the message body. | |
44 * | |
45 * @param ResponseInterface $response | |
46 */ | |
47 private function emitBody(ResponseInterface $response) | |
48 { | |
49 echo $response->getBody(); | |
50 } | |
51 } |