1 | <?php |
||
11 | class Response |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * Response code |
||
16 | * |
||
17 | * @var int |
||
18 | */ |
||
19 | private $code = 200; |
||
20 | |||
21 | /** |
||
22 | * Page title |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | private $title = ''; |
||
27 | |||
28 | /** |
||
29 | * Response content |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | private $body = ''; |
||
34 | |||
35 | /** |
||
36 | * Response content type |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $type = 'text/html'; |
||
41 | |||
42 | /** |
||
43 | * Response encoding |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | private $encoding = 'utf-8'; |
||
48 | |||
49 | /** |
||
50 | * Additional headers to be send to client |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | private $additionalHeaders = array(); |
||
55 | |||
56 | /** |
||
57 | * Retrieve the response body as string |
||
58 | * |
||
59 | * @return string The response content |
||
60 | */ |
||
61 | 20 | public function __toString() |
|
65 | |||
66 | /** |
||
67 | * Retrieve the response code |
||
68 | * |
||
69 | * @return int |
||
70 | */ |
||
71 | 13 | public function getCode() |
|
75 | |||
76 | /** |
||
77 | * Set the response code |
||
78 | * |
||
79 | * @param int $code |
||
80 | * |
||
81 | * @return \Nkey\Caribu\Mvc\Controller\Response The response |
||
82 | */ |
||
83 | 5 | public function setCode($code) |
|
88 | |||
89 | /** |
||
90 | * Retrieve response body |
||
91 | * |
||
92 | * @return string |
||
93 | */ |
||
94 | 20 | public function getBody() |
|
98 | |||
99 | /** |
||
100 | * Set the response body content |
||
101 | * |
||
102 | * @param string $body |
||
103 | * The content body |
||
104 | * |
||
105 | * @return \Nkey\Caribu\Mvc\Controller\Response The response |
||
106 | */ |
||
107 | 20 | public function setBody($body) |
|
112 | |||
113 | /** |
||
114 | * Append some content to existing body |
||
115 | * |
||
116 | * @param string $body |
||
117 | * The content body to append to existing content |
||
118 | * |
||
119 | * @return \Nkey\Caribu\Mvc\Controller\Response |
||
120 | */ |
||
121 | 20 | public function appendBody($body) |
|
125 | |||
126 | /** |
||
127 | * Return the reponse as http status code string |
||
128 | * |
||
129 | * @return string The status code |
||
130 | */ |
||
131 | 20 | public function getHttpCode() |
|
135 | |||
136 | /** |
||
137 | * Retrieve the content type |
||
138 | * |
||
139 | * @return string The mimetype of response |
||
140 | */ |
||
141 | 20 | public function getType() |
|
145 | |||
146 | /** |
||
147 | * Set the response type |
||
148 | * |
||
149 | * @param string $type |
||
150 | * The mimetype of response |
||
151 | * |
||
152 | * @return \Nkey\Caribu\Mvc\Controller\Response The response |
||
153 | */ |
||
154 | 2 | public function setType($type) |
|
159 | |||
160 | /** |
||
161 | * Set the page title |
||
162 | * |
||
163 | * @param string $title |
||
164 | * The page title |
||
165 | * |
||
166 | * @return \Nkey\Caribu\Mvc\Controller\Response The response |
||
167 | */ |
||
168 | 29 | public function setTitle($title) |
|
173 | |||
174 | /** |
||
175 | * Retrieve page title |
||
176 | * |
||
177 | * @return string The page title |
||
178 | */ |
||
179 | 18 | public function getTitle() |
|
183 | |||
184 | /** |
||
185 | * Append an additional header to list |
||
186 | * |
||
187 | * @param string $headerName The name of the header |
||
188 | * @param string $headerValue The value of the header |
||
189 | * |
||
190 | * @return Response The current response |
||
191 | */ |
||
192 | public function addHeader($headerName, $headerValue) |
||
193 | { |
||
194 | $this->additionalHeaders[$headerName] = $headerValue; |
||
195 | return $this; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Retrieve the list of additional headers |
||
200 | * |
||
201 | * @return array The list of headers |
||
202 | */ |
||
203 | public function getAdditionalHeaders() |
||
204 | { |
||
205 | return $this->additionalHeaders; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Set the response content encoding |
||
210 | * |
||
211 | * @param string $encoding |
||
212 | * |
||
213 | * @return Response The current response |
||
214 | */ |
||
215 | public function setEncoding($encoding) |
||
220 | |||
221 | /** |
||
222 | * Retrieve the content encoding |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | 20 | public function getEncoding() |
|
230 | } |
||
231 |