ResponseResolver::setViewEngineConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace App\ViewResolver;
4
5
use Core\View\ViewResolverInterface;
6
use Core\Utils\ResponseProxy;
7
use Psr\Http\Message\ResponseInterface;
8
9
class ResponseResolver implements ViewResolverInterface
10
{
11
    /**
12
     * @var ResponseProxy
13
     */
14
    private static $responseProxy = null;
15
16
    public static function getResponseProxyInstance()
17
    {
18
        if (self::$responseProxy === null) {
19
            self::$responseProxy = new ResponseProxy();
20
        }
21
22
        return self::$responseProxy;
23
    }
24
25
    public function setViewEngineConfig(array $settings)
26
    {
27
    }
28
29
    public function resolve($viewData)
30
    {
31
        if (self::$responseProxy === null || self::$responseProxy->getResponse() === null) {
32
            return;
33
        }
34
35
        /** @var ResponseInterface */
36
        $response = self::$responseProxy->getResponse();
37
38
        if ($response->getStatusCode()) {
39
            header(sprintf('HTTP/%s %d %s',
40
                $response->getProtocolVersion(),
41
                $response->getStatusCode(),
42
                $response->getReasonPhrase()
43
            ));
44
        }
45
46
        foreach ($response->getHeaders() as $name => $values) {
47
            foreach ($values as $value) {
48
                header($name . ':' . $value);
49
            }
50
        }
51
    }
52
}
53