@@ -133,12 +133,12 @@ |
||
| 133 | 133 | { |
| 134 | 134 | $body = 'Example body'; |
| 135 | 135 | $response = $this->createResponse(200, [], $body) |
| 136 | - ->withHeader('X-Test', '1') |
|
| 137 | - ->withAddedHeader('X-Test', '2') |
|
| 138 | - ->withAddedHeader('X-Test', '3; 3.5') |
|
| 139 | - ->withHeader('Cookie-Set', '1') |
|
| 140 | - ->withAddedHeader('cookie-Set', '2') |
|
| 141 | - ->withAddedHeader('Cookie-set', '3'); |
|
| 136 | + ->withHeader('X-Test', '1') |
|
| 137 | + ->withAddedHeader('X-Test', '2') |
|
| 138 | + ->withAddedHeader('X-Test', '3; 3.5') |
|
| 139 | + ->withHeader('Cookie-Set', '1') |
|
| 140 | + ->withAddedHeader('cookie-Set', '2') |
|
| 141 | + ->withAddedHeader('Cookie-set', '3'); |
|
| 142 | 142 | |
| 143 | 143 | (new SapiEmitter(new HttpConfig(['chunkSize' => null])))->emit($response); |
| 144 | 144 | $this->assertEquals(200, $this->getResponseCode()); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->assertEquals(200, $this->getResponseCode()); |
| 67 | 67 | $this->assertCount(2, $this->getHeaders()); |
| 68 | 68 | $this->assertContains('X-Test: 1', $this->getHeaders()); |
| 69 | - $this->assertContains('Content-Length: ' . $length, $this->getHeaders()); |
|
| 69 | + $this->assertContains('Content-Length: '.$length, $this->getHeaders()); |
|
| 70 | 70 | $this->expectOutputString('Example body'); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | $this->expectException(EmitterException::class); |
| 120 | 120 | $this->expectExceptionMessage('Unable to emit response, found non closed buffered output.'); |
| 121 | 121 | |
| 122 | - try { |
|
| 122 | + try{ |
|
| 123 | 123 | echo 'some data'; |
| 124 | 124 | $this->createEmitter()->emit($response); |
| 125 | - } catch (\Throwable $e) { |
|
| 125 | + }catch (\Throwable $e){ |
|
| 126 | 126 | throw $e; |
| 127 | - } finally { |
|
| 127 | + }finally{ |
|
| 128 | 128 | \ob_end_clean(); |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | private function createEmitter(?int $bufferSize = null): SapiEmitter |
| 175 | 175 | { |
| 176 | 176 | $emitter = new SapiEmitter(new HttpConfig(['chunkSize' => null])); |
| 177 | - if ($bufferSize !== null) { |
|
| 177 | + if ($bufferSize !== null){ |
|
| 178 | 178 | $emitter->bufferSize = $bufferSize; |
| 179 | 179 | } |
| 180 | 180 | return $emitter; |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | $response = (new Response()) |
| 190 | 190 | ->withStatus($status) |
| 191 | 191 | ->withProtocolVersion($version); |
| 192 | - foreach ($headers as $header => $value) { |
|
| 192 | + foreach ($headers as $header => $value){ |
|
| 193 | 193 | $response = $response->withHeader($header, $value); |
| 194 | 194 | } |
| 195 | - if ($body instanceof StreamInterface) { |
|
| 195 | + if ($body instanceof StreamInterface){ |
|
| 196 | 196 | $response = $response->withBody($body); |
| 197 | - } elseif (is_string($body)) { |
|
| 197 | + } elseif (is_string($body)){ |
|
| 198 | 198 | $response->getBody()->write($body); |
| 199 | 199 | } |
| 200 | 200 | return $response; |
@@ -119,12 +119,17 @@ discard block |
||
| 119 | 119 | $this->expectException(EmitterException::class); |
| 120 | 120 | $this->expectExceptionMessage('Unable to emit response, found non closed buffered output.'); |
| 121 | 121 | |
| 122 | - try { |
|
| 122 | + try |
|
| 123 | + { |
|
| 123 | 124 | echo 'some data'; |
| 124 | 125 | $this->createEmitter()->emit($response); |
| 125 | - } catch (\Throwable $e) { |
|
| 126 | + } |
|
| 127 | + catch (\Throwable $e) |
|
| 128 | + { |
|
| 126 | 129 | throw $e; |
| 127 | - } finally { |
|
| 130 | + } |
|
| 131 | + finally |
|
| 132 | + { |
|
| 128 | 133 | \ob_end_clean(); |
| 129 | 134 | } |
| 130 | 135 | } |
@@ -174,7 +179,8 @@ discard block |
||
| 174 | 179 | private function createEmitter(?int $bufferSize = null): SapiEmitter |
| 175 | 180 | { |
| 176 | 181 | $emitter = new SapiEmitter(new HttpConfig(['chunkSize' => null])); |
| 177 | - if ($bufferSize !== null) { |
|
| 182 | + if ($bufferSize !== null) |
|
| 183 | + { |
|
| 178 | 184 | $emitter->bufferSize = $bufferSize; |
| 179 | 185 | } |
| 180 | 186 | return $emitter; |
@@ -189,12 +195,16 @@ discard block |
||
| 189 | 195 | $response = (new Response()) |
| 190 | 196 | ->withStatus($status) |
| 191 | 197 | ->withProtocolVersion($version); |
| 192 | - foreach ($headers as $header => $value) { |
|
| 198 | + foreach ($headers as $header => $value) |
|
| 199 | + { |
|
| 193 | 200 | $response = $response->withHeader($header, $value); |
| 194 | 201 | } |
| 195 | - if ($body instanceof StreamInterface) { |
|
| 202 | + if ($body instanceof StreamInterface) |
|
| 203 | + { |
|
| 196 | 204 | $response = $response->withBody($body); |
| 197 | - } elseif (is_string($body)) { |
|
| 205 | + } |
|
| 206 | + elseif (is_string($body)) |
|
| 207 | + { |
|
| 198 | 208 | $response->getBody()->write($body); |
| 199 | 209 | } |
| 200 | 210 | return $response; |
@@ -58,6 +58,6 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | public function getChunkSize(): ?int |
| 60 | 60 | { |
| 61 | - return !\is_null($this->config['chunkSize']) ? (int) $this->config['chunkSize'] : null; |
|
| 61 | + return !\is_null($this->config['chunkSize']) ? (int)$this->config['chunkSize'] : null; |
|
| 62 | 62 | } |
| 63 | 63 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | public function __construct(HttpConfig $config) |
| 34 | 34 | { |
| 35 | - if (($chunkSize = $config->getChunkSize()) !== null) { |
|
| 35 | + if (($chunkSize = $config->getChunkSize()) !== null){ |
|
| 36 | 36 | $this->bufferSize = $chunkSize; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | private function emitBody(ResponseInterface $response): void |
| 63 | 63 | { |
| 64 | 64 | $body = $response->getBody(); |
| 65 | - if ($body->isSeekable()) { |
|
| 65 | + if ($body->isSeekable()){ |
|
| 66 | 66 | $body->rewind(); |
| 67 | 67 | } |
| 68 | - if (!$body->isReadable()) { |
|
| 68 | + if (!$body->isReadable()){ |
|
| 69 | 69 | return; |
| 70 | 70 | } |
| 71 | - while (!$body->eof()) { |
|
| 71 | + while (!$body->eof()){ |
|
| 72 | 72 | echo $body->read($this->bufferSize); |
| 73 | 73 | flush(); |
| 74 | 74 | } |
@@ -85,11 +85,11 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | private function assertNoPreviousOutput(): void |
| 87 | 87 | { |
| 88 | - if (headers_sent()) { |
|
| 88 | + if (headers_sent()){ |
|
| 89 | 89 | throw new EmitterException('Unable to emit response, headers already send.'); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
| 92 | + if (ob_get_level() > 0 && ob_get_length() > 0){ |
|
| 93 | 93 | throw new EmitterException('Unable to emit response, found non closed buffered output.'); |
| 94 | 94 | } |
| 95 | 95 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | 'HTTP/%s %d%s', |
| 116 | 116 | $response->getProtocolVersion(), |
| 117 | 117 | $statusCode, |
| 118 | - ($reasonPhrase ? ' ' . $reasonPhrase : '') |
|
| 118 | + ($reasonPhrase ? ' '.$reasonPhrase : '') |
|
| 119 | 119 | ), true, $statusCode); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | { |
| 134 | 134 | $statusCode = $response->getStatusCode(); |
| 135 | 135 | |
| 136 | - foreach ($response->getHeaders() as $header => $values) { |
|
| 136 | + foreach ($response->getHeaders() as $header => $values){ |
|
| 137 | 137 | $name = $this->filterHeader($header); |
| 138 | 138 | $first = $name === 'Set-Cookie' ? false : true; |
| 139 | - foreach ($values as $value) { |
|
| 139 | + foreach ($values as $value){ |
|
| 140 | 140 | header(sprintf( |
| 141 | 141 | '%s: %s', |
| 142 | 142 | $name, |
@@ -32,7 +32,8 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | public function __construct(HttpConfig $config) |
| 34 | 34 | { |
| 35 | - if (($chunkSize = $config->getChunkSize()) !== null) { |
|
| 35 | + if (($chunkSize = $config->getChunkSize()) !== null) |
|
| 36 | + { |
|
| 36 | 37 | $this->bufferSize = $chunkSize; |
| 37 | 38 | } |
| 38 | 39 | } |
@@ -62,13 +63,16 @@ discard block |
||
| 62 | 63 | private function emitBody(ResponseInterface $response): void |
| 63 | 64 | { |
| 64 | 65 | $body = $response->getBody(); |
| 65 | - if ($body->isSeekable()) { |
|
| 66 | + if ($body->isSeekable()) |
|
| 67 | + { |
|
| 66 | 68 | $body->rewind(); |
| 67 | 69 | } |
| 68 | - if (!$body->isReadable()) { |
|
| 70 | + if (!$body->isReadable()) |
|
| 71 | + { |
|
| 69 | 72 | return; |
| 70 | 73 | } |
| 71 | - while (!$body->eof()) { |
|
| 74 | + while (!$body->eof()) |
|
| 75 | + { |
|
| 72 | 76 | echo $body->read($this->bufferSize); |
| 73 | 77 | flush(); |
| 74 | 78 | } |
@@ -85,11 +89,13 @@ discard block |
||
| 85 | 89 | */ |
| 86 | 90 | private function assertNoPreviousOutput(): void |
| 87 | 91 | { |
| 88 | - if (headers_sent()) { |
|
| 92 | + if (headers_sent()) |
|
| 93 | + { |
|
| 89 | 94 | throw new EmitterException('Unable to emit response, headers already send.'); |
| 90 | 95 | } |
| 91 | 96 | |
| 92 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
| 97 | + if (ob_get_level() > 0 && ob_get_length() > 0) |
|
| 98 | + { |
|
| 93 | 99 | throw new EmitterException('Unable to emit response, found non closed buffered output.'); |
| 94 | 100 | } |
| 95 | 101 | } |
@@ -133,10 +139,12 @@ discard block |
||
| 133 | 139 | { |
| 134 | 140 | $statusCode = $response->getStatusCode(); |
| 135 | 141 | |
| 136 | - foreach ($response->getHeaders() as $header => $values) { |
|
| 142 | + foreach ($response->getHeaders() as $header => $values) |
|
| 143 | + { |
|
| 137 | 144 | $name = $this->filterHeader($header); |
| 138 | 145 | $first = $name === 'Set-Cookie' ? false : true; |
| 139 | - foreach ($values as $value) { |
|
| 146 | + foreach ($values as $value) |
|
| 147 | + { |
|
| 140 | 148 | header(sprintf( |
| 141 | 149 | '%s: %s', |
| 142 | 150 | $name, |