1 | <?php |
||
7 | class Response |
||
8 | { |
||
9 | /** |
||
10 | * @var \React\Http\Response |
||
11 | */ |
||
12 | private $httpResponse; |
||
13 | |||
14 | private $server; |
||
15 | private $version; |
||
16 | |||
17 | /** |
||
18 | * Status code of the response |
||
19 | * @var int |
||
20 | */ |
||
21 | private $status = 200; |
||
22 | |||
23 | /** |
||
24 | * Array of headers to send |
||
25 | * @var array |
||
26 | */ |
||
27 | private $headers = []; |
||
28 | |||
29 | /** |
||
30 | * The content-length |
||
31 | * @var int |
||
32 | */ |
||
33 | private $contentLength = 0; |
||
34 | |||
35 | /** |
||
36 | * Data to send |
||
37 | * @var string |
||
38 | */ |
||
39 | private $data; |
||
40 | |||
41 | /** |
||
42 | * Check if headers are already sent |
||
43 | * @var bool |
||
44 | */ |
||
45 | private $headersSent = false; |
||
46 | |||
47 | /** |
||
48 | * Create a new Restify/Response object |
||
49 | * |
||
50 | * @param \React\Http\Response $response |
||
51 | * |
||
52 | */ |
||
53 | public function __construct(HttpResponse $response, $server = null, $version = null) |
||
59 | |||
60 | /** |
||
61 | * Add a header to the response |
||
62 | * |
||
63 | * @param string $name |
||
64 | * @param string $value |
||
65 | * |
||
66 | * @return Response |
||
67 | */ |
||
68 | public function addHeader($name, $value) |
||
74 | |||
75 | /** |
||
76 | * Set the status code of the response |
||
77 | * |
||
78 | * @param int $code |
||
79 | * @return Response |
||
80 | */ |
||
81 | public function setStatus($code) |
||
87 | |||
88 | /** |
||
89 | * is the response writable ? |
||
90 | * |
||
91 | * @return boolean |
||
92 | */ |
||
93 | public function isWritable() |
||
97 | |||
98 | /** |
||
99 | * Write a HTTP 100 (continue) header |
||
100 | * |
||
101 | * @return Reponse |
||
102 | */ |
||
103 | public function writeContinue() |
||
109 | |||
110 | /** |
||
111 | * Write data to the response |
||
112 | * |
||
113 | * @param string $data |
||
114 | * @return Reponse |
||
115 | */ |
||
116 | public function write($data) |
||
123 | |||
124 | /** |
||
125 | * Write json to the response |
||
126 | * |
||
127 | * @param mixed $data |
||
128 | * @return Reponse |
||
129 | */ |
||
130 | public function writeJson($data) |
||
139 | |||
140 | /** |
||
141 | * Empty current response |
||
142 | * |
||
143 | * @return Reponse |
||
144 | */ |
||
145 | public function reset() |
||
154 | |||
155 | /** |
||
156 | * End the connexion |
||
157 | */ |
||
158 | public function end() |
||
164 | |||
165 | /** |
||
166 | * Close the connexion |
||
167 | */ |
||
168 | public function close() |
||
174 | |||
175 | /** |
||
176 | * Send all headers to the response |
||
177 | */ |
||
178 | public function sendHeaders() |
||
191 | |||
192 | public function sendContentLengthHeaders() |
||
208 | } |
||
209 |