1+ <?php
2+ /*
3+ A simple RESTful webservices base class
4+ Use this as a template and build upon it
5+ */
6+ class SimpleRest {
7+
8+ private $ httpVersion = "HTTP/1.1 " ;
9+
10+ public function setHttpHeaders ($ contentType , $ statusCode ){
11+
12+ $ statusMessage = $ this -> getHttpStatusMessage ($ statusCode );
13+
14+ header ($ this ->httpVersion . " " . $ statusCode ." " . $ statusMessage );
15+ header ("Content-Type: " . $ contentType );
16+ }
17+
18+ public function getHttpStatusMessage ($ statusCode ){
19+ $ httpStatus = array (
20+ 100 => 'Continue ' ,
21+ 101 => 'Switching Protocols ' ,
22+ 200 => 'OK ' ,
23+ 201 => 'Created ' ,
24+ 202 => 'Accepted ' ,
25+ 203 => 'Non-Authoritative Information ' ,
26+ 204 => 'No Content ' ,
27+ 205 => 'Reset Content ' ,
28+ 206 => 'Partial Content ' ,
29+ 300 => 'Multiple Choices ' ,
30+ 301 => 'Moved Permanently ' ,
31+ 302 => 'Found ' ,
32+ 303 => 'See Other ' ,
33+ 304 => 'Not Modified ' ,
34+ 305 => 'Use Proxy ' ,
35+ 306 => '(Unused) ' ,
36+ 307 => 'Temporary Redirect ' ,
37+ 400 => 'Bad Request ' ,
38+ 401 => 'Unauthorized ' ,
39+ 402 => 'Payment Required ' ,
40+ 403 => 'Forbidden ' ,
41+ 404 => 'Not Found ' ,
42+ 405 => 'Method Not Allowed ' ,
43+ 406 => 'Not Acceptable ' ,
44+ 407 => 'Proxy Authentication Required ' ,
45+ 408 => 'Request Timeout ' ,
46+ 409 => 'Conflict ' ,
47+ 410 => 'Gone ' ,
48+ 411 => 'Length Required ' ,
49+ 412 => 'Precondition Failed ' ,
50+ 413 => 'Request Entity Too Large ' ,
51+ 414 => 'Request-URI Too Long ' ,
52+ 415 => 'Unsupported Media Type ' ,
53+ 416 => 'Requested Range Not Satisfiable ' ,
54+ 417 => 'Expectation Failed ' ,
55+ 500 => 'Internal Server Error ' ,
56+ 501 => 'Not Implemented ' ,
57+ 502 => 'Bad Gateway ' ,
58+ 503 => 'Service Unavailable ' ,
59+ 504 => 'Gateway Timeout ' ,
60+ 505 => 'HTTP Version Not Supported ' );
61+ return ($ httpStatus [$ statusCode ]) ? $ httpStatus [$ statusCode ] : $ status [500 ];
62+ }
63+ }
64+ ?>
0 commit comments