EmitterDecorator::emit()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the jade/jade package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jade\HttpKernel;
13
14
use Psr\Http\Message\ResponseInterface;
15
use Zend\HttpHandlerRunner\Emitter\EmitterInterface;
16
use Zend\HttpHandlerRunner\Emitter\SapiEmitter;
17
use Zend\HttpHandlerRunner\Emitter\SapiStreamEmitter;
18
19
class EmitterDecorator implements EmitterInterface
20
{
21
    protected $emitter;
22
    protected $streamEmitter;
23
24
    public function __construct(SapiEmitter $emitter, SapiStreamEmitter $streamEmitter)
25
    {
26
        $this->emitter = $emitter;
27
        $this->streamEmitter = $streamEmitter;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function emit(ResponseInterface $response) : bool
34
    {
35
        if (! $response->hasHeader('Content-Disposition')
36
            && ! $response->hasHeader('Content-Range')
37
        ) {
38
            return $this->emitter->emit($response);
39
        }
40
        // 内存优化型 response 输出
41
        return $this->streamEmitter->emit($response);
42
    }
43
}