Response::sendOutput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace System\Http;
4
5
use System\Application;
6
7
class Response
8
{
9
    /**
10
     * Application Object
11
     *
12
     * @var \System\Application
13
     */
14
    private $app;
15
16
    /**
17
     * Headers container will be sent to the browser
18
     *
19
     * @var array
20
     */
21
    private $headers = [];
22
23
    /**
24
     * The content will be sent to the browser
25
     *
26
     * @var string
27
     */
28
    private $content = '';
29
30
    /**
31
     * Constructor
32
     *
33
     * @param \System\Application $app
34
     */
35
    public function __construct(Application $app)
36
    {
37
        $this->app = $app;
38
    }
39
40
    /**
41
     * Set the response output content
42
     *
43
     * @param string $content
44
     * @return void
45
     */
46
    public function setOutput(string $content)
47
    {
48
        $this->content = $content;
49
    }
50
51
    /**
52
     * Set the response Headers
53
     *
54
     * @param string $header
55
     * @param mixed $value
56
     * @return void
57
     */
58
    public function setHeader(string $header, $value = '')
59
    {
60
        $this->headers[$header] = $value;
61
    }
62
63
    /**
64
     * Send the response headers and content
65
     *
66
     * @return void
67
     */
68
    public function send()
69
    {
70
        $this->sendHeaders();
71
72
        $this->sendOutput();
73
    }
74
75
    /**
76
     * Send the response headers
77
     *
78
     * @return void
79
     */
80
    private function sendHeaders()
81
    {
82
        foreach ($this->headers as $header => $value) {
83
            $value = !$value ?: ':' . $value;
84
85
            header($header . $value);
86
        }
87
    }
88
89
    /**
90
     * Send the response output
91
     *
92
     * @return void
93
     */
94
    private function sendOutput()
95
    {
96
        echo $this->content;
97
        exit;
98
    }
99
}
100