1 | <?php |
||
5 | class HttpResponse |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var ResponseBag |
||
10 | */ |
||
11 | protected $response; |
||
12 | |||
13 | /** |
||
14 | * @var ResponseBag |
||
15 | */ |
||
16 | protected $responseDebug; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $headers = []; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $responseCode = 200; |
||
27 | |||
28 | public function __construct() |
||
32 | |||
33 | /** |
||
34 | * Add a value in session |
||
35 | * |
||
36 | * @param string $name |
||
37 | * @param string $value |
||
38 | */ |
||
39 | public function setSession($name, $value) |
||
43 | |||
44 | /** |
||
45 | * Remove a value in this session |
||
46 | * |
||
47 | * @param string $name |
||
48 | */ |
||
49 | public function removeSession($name) |
||
53 | |||
54 | /** |
||
55 | * Add a cookie value |
||
56 | * |
||
57 | * @param string $name |
||
58 | * @param string $value |
||
59 | * @param int $expire (seconds from now) |
||
60 | * @param int $path (directory into domain in which the cookie will be available on ) |
||
61 | * @param string $domain |
||
62 | */ |
||
63 | public function addCookie($name, $value, $expire = null, $path = null, $domain = null) |
||
70 | |||
71 | /** |
||
72 | * Delete a cookie |
||
73 | * |
||
74 | * @param string $name |
||
75 | */ |
||
76 | public function removeCookie($name) |
||
81 | |||
82 | /** |
||
83 | * ResponseBag is a collection of objects will be returned to the client. RestServer call handle the ResponseBag to |
||
84 | * return the proper output. Avoid to use it directly here. Prefer the methods write or writeDebug; |
||
85 | * |
||
86 | * @return ResponseBag |
||
87 | */ |
||
88 | public function getResponseBag() |
||
92 | |||
93 | /** |
||
94 | * Add an array, model or stdClass to be processed. |
||
95 | * |
||
96 | * @param mixed $object |
||
97 | */ |
||
98 | public function write($object) |
||
102 | |||
103 | /** |
||
104 | * Added informations for debug purposes only. In case the error it will showed and the result a node called "debug" will be added. |
||
105 | * |
||
106 | * @param string $key |
||
107 | * @param mixed $string |
||
108 | */ |
||
109 | public function writeDebug($key, $string) |
||
118 | |||
119 | public function emptyResponse() |
||
123 | |||
124 | public function addHeader($header, $value) |
||
128 | |||
129 | public function getHeaders() |
||
142 | |||
143 | public function setResponseCode($code) |
||
147 | |||
148 | public function getResponseCode() |
||
152 | } |
||
153 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: