EmitterDecorator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A emit() 0 10 3
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
}