| Total Complexity | 7 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class StreamResponse extends Response |
||
| 9 | { |
||
| 10 | const BUFFER_SIZE = 4096; |
||
| 11 | |||
| 12 | private $bufferSize; |
||
| 13 | |||
| 14 | public function __construct(ResponseInterface $response, $bufferSize = self::BUFFER_SIZE) |
||
| 15 | { |
||
| 16 | parent::__construct(null, $response->getStatusCode(), $response->getHeaders()); |
||
| 17 | |||
| 18 | $this->content = $response->getBody(); |
||
| 19 | $this->bufferSize = $bufferSize; |
||
| 20 | } |
||
| 21 | |||
| 22 | public function sendContent() |
||
| 23 | { |
||
| 24 | $chunked = $this->headers->has('Transfer-Encoding'); |
||
| 25 | $this->content->seek(0); |
||
| 26 | |||
| 27 | for (; ;) { |
||
| 28 | $chunk = $this->content->read($this->bufferSize); |
||
| 29 | |||
| 30 | if ($chunked) { |
||
| 31 | echo sprintf("%x\r\n", strlen($chunk)); |
||
| 32 | } |
||
| 33 | |||
| 34 | echo $chunk; |
||
| 35 | |||
| 36 | if ($chunked) { |
||
| 37 | echo "\r\n"; |
||
| 38 | } |
||
| 39 | |||
| 40 | flush(); |
||
| 41 | |||
| 42 | if (!$chunk) { |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | public function getContent() |
||
| 51 | } |
||
| 52 | } |