Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Emitter | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
10 / 10 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
100.00% |
1 / 1 |
3 | |||||
| emit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Core; |
| 6 | |
| 7 | use Laminas\HttpHandlerRunner\Emitter\EmitterInterface; |
| 8 | use Laminas\HttpHandlerRunner\Emitter\EmitterStack; |
| 9 | use Laminas\HttpHandlerRunner\Emitter\SapiEmitter; |
| 10 | use Laminas\HttpHandlerRunner\Emitter\SapiStreamEmitter; |
| 11 | use Override; |
| 12 | use Psr\Http\Message\ResponseInterface; |
| 13 | |
| 14 | final class Emitter implements EmitterInterface |
| 15 | { |
| 16 | protected EmitterStack $stack; |
| 17 | |
| 18 | public function __construct(int $maxBufferLength = 8192) |
| 19 | { |
| 20 | $sapiStreamEmitter = new SapiStreamEmitter($maxBufferLength); |
| 21 | $conditionalEmitter = new class($sapiStreamEmitter) implements EmitterInterface { |
| 22 | private EmitterInterface $emitter; |
| 23 | |
| 24 | public function __construct(EmitterInterface $emitter) |
| 25 | { |
| 26 | $this->emitter = $emitter; |
| 27 | } |
| 28 | |
| 29 | #[Override] |
| 30 | public function emit(ResponseInterface $response): bool |
| 31 | { |
| 32 | if (!$response->hasHeader('Content-Disposition') && !$response->hasHeader('Content-Range')) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | return $this->emitter->emit($response); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | $this->stack = new EmitterStack(); |
| 41 | $this->stack->push(new SapiEmitter()); |
| 42 | $this->stack->push($conditionalEmitter); |
| 43 | } |
| 44 | |
| 45 | #[Override] |
| 46 | public function emit(ResponseInterface $response): bool |
| 47 | { |
| 48 | return $this->stack->emit($response); |
| 49 | } |
| 50 | } |