This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Response.php
executable file
·289 lines (240 loc) · 6.53 KB
/
Response.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/**
* provides named constants for
* HTTP protocol status codes.
*
*/
class REST_Response extends Zend_Controller_Response_Http
{
// Informational 1xx
const HTTP_CONTINUE = 100;
const SWITCH_PROTOCOLS = 101;
// Successful 2xx
const OK = 200;
const CREATED = 201;
const ACCEPTED = 202;
const NONAUTHORITATIVE = 203;
const NO_CONTENT = 204;
const RESET_CONTENT = 205;
const PARTIAL_CONTENT = 206;
// Redirection 3xx
const MULTIPLE_CHOICES = 300;
const MOVED_PERMANENTLY = 301;
const FOUND = 302;
const SEE_OTHER = 303;
const NOT_MODIFIED = 304;
const USE_PROXY = 305;
// 306 is deprecated but reserved
const TEMP_REDIRECT = 307;
// Client Error 4xx
const BAD_REQUEST = 400;
const UNAUTHORIZED = 401;
const PAYMENT_REQUIRED = 402;
const FORBIDDEN = 403;
const NOT_FOUND = 404;
const NOT_ALLOWED = 405;
const NOT_ACCEPTABLE = 406;
const PROXY_AUTH_REQUIRED = 407;
const REQUEST_TIMEOUT = 408;
const CONFLICT = 409;
const GONE = 410;
const LENGTH_REQUIRED = 411;
const PRECONDITION_FAILED = 412;
const LARGE_REQUEST_ENTITY = 413;
const LONG_REQUEST_URI = 414;
const UNSUPPORTED_TYPE = 415;
const UNSATISFIABLE_RANGE = 416;
const EXPECTATION_FAILED = 417;
// Server Error 5xx
const SERVER_ERROR = 500;
const NOT_IMPLEMENTED = 501;
const BAD_GATEWAY = 502;
const UNAVAILABLE = 503;
const GATEWAY_TIMEOUT = 504;
const UNSUPPORTED_VERSION = 505;
const BANDWIDTH_EXCEEDED = 509;
// Informational 1xx
function httpContinue()
{
$this->setHttpResponseCode(self::HTTP_CONTINUE);
}
function switchProtocols()
{
$this->setHttpResponseCode(self::SWITCH_PROTOCOLS);
}
// Successful 2xx
public function Ok()
{
$this->setHttpResponseCode(self::OK);
}
public function created()
{
$this->setHttpResponseCode(self::CREATED);
}
public function accepted()
{
$this->setHttpResponseCode(self::ACCEPTED);
}
public function nonAuthoritative()
{
$this->setHttpResponseCode(self::NONAUTHORITATIVE);
}
public function noContent()
{
$this->setHttpResponseCode(self::NO_CONTENT);
}
public function resetContent()
{
$this->setHttpResponseCode(self::RESET_CONTENT);
}
public function partialContent()
{
$this->setHttpResponseCode(self::PARTIAL_CONTENT);
}
// Redirection 3xx
public function multipleChoices()
{
$this->setHttpResponseCode(self::MULTIPLE_CHOICES);
}
public function movedPermanently()
{
$this->setHttpResponseCode(self::MOVED_PERMANENTLY);
}
public function found()
{
$this->setHttpResponseCode(self::FOUND);
}
public function seeOther()
{
$this->setHttpResponseCode(self::NO_CONTENT);
}
public function notModified()
{
$this->setHttpResponseCode(self::NOT_MODIFIED);
}
public function useProxy()
{
$this->setHttpResponseCode(self::USE_PROXY);
}
public function tempRedirect()
{
$this->setHttpResponseCode(self::TEMP_REDIRECT);
}
// Client Error 4xx
public function badRequest()
{
$this->setHttpResponseCode(self::BAD_REQUEST);
}
public function unauthorized()
{
$this->setHttpResponseCode(self::UNAUTHORIZED);
}
public function paymentRequired()
{
$this->setHttpResponseCode(self::PAYMENT_REQUIRED);
}
public function forbidden()
{
$this->setHttpResponseCode(self::FORBIDDEN);
}
public function notFound()
{
$this->setHttpResponseCode(self::NOT_FOUND);
}
public function notAllowed()
{
$this->setHttpResponseCode(self::NOT_ALLOWED);
}
public function notAcceptable()
{
$this->setHttpResponseCode(self::NOT_ACCEPTABLE);
}
public function proxyAuthRequired()
{
$this->setHttpResponseCode(self::PROXY_AUTH_REQUIRED);
}
public function requestTimeout()
{
$this->setHttpResponseCode(self::REQUEST_TIMEOUT);
}
public function conflict()
{
$this->setHttpResponseCode(self::CONFLICT);
}
public function gone()
{
$this->setHttpResponseCode(self::GONE);
}
public function lengthRequired()
{
$this->setHttpResponseCode(self::NO_CONTENT);
}
public function preconditionFailed()
{
$this->setHttpResponseCode(self::PRECONDITION_FAILED);
}
public function largeRequestEntity()
{
$this->setHttpResponseCode(self::LARGE_REQUEST_ENTITY);
}
public function longRequestUri()
{
$this->setHttpResponseCode(self::LONG_REQUEST_URI);
}
public function unsupportedType()
{
$this->setHttpResponseCode(self::UNSUPPORTED_TYPE);
}
public function unsatisfiableRange()
{
$this->setHttpResponseCode(self::UNSATISFIABLE_RANGE);
}
public function expectationFailed()
{
$this->setHttpResponseCode(self::EXPECTATION_FAILED);
}
// Server Error 5xx
public function serverError()
{
$this->setHttpResponseCode(self::SERVER_ERROR);
}
public function notImplemented()
{
$this->setHttpResponseCode(self::NOT_IMPLEMENTED);
}
public function badGateway()
{
$this->setHttpResponseCode(self::BAD_GATEWAY);
}
public function unavailable()
{
$this->setHttpResponseCode(self::UNAVAILABLE);
}
public function gatewayTimeout()
{
$this->setHttpResponseCode(self::GATEWAY_TIMEOUT);
}
public function unsupportedVersion()
{
$this->setHttpResponseCode(self::UNSUPPORTED_VERSION);
}
public function bandwidthExceeded()
{
$this->setHttpResponseCode(self::BANDWIDTH_EXCEEDED);
}
/**
* Return header value (if set); see {@link $_headers} for format
*
* @return string | boolean
*/
public function getHeaderValue($name)
{
foreach ($this->_headers as $key => $header) {
if ($name == $header['name']) {
return $header['value'];
}
}
return false;
}
}
?>