Total Complexity | 7 |
Total Lines | 88 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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($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($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 | header($header . ':' . $value); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Send the response output |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | private function sendOutput() |
||
95 | } |
||
96 | } |
||
97 |