diff options
Diffstat (limited to 'core/helpers')
-rw-r--r-- | core/helpers/MY_url.php | 2 | ||||
-rw-r--r-- | core/helpers/rest.php | 59 |
2 files changed, 57 insertions, 4 deletions
diff --git a/core/helpers/MY_url.php b/core/helpers/MY_url.php index bcdef4c5..a7746ff0 100644 --- a/core/helpers/MY_url.php +++ b/core/helpers/MY_url.php @@ -32,4 +32,4 @@ class url extends url_Core { public static function abs_site($path) { return url::site($path, "http"); } -}
\ No newline at end of file +} diff --git a/core/helpers/rest.php b/core/helpers/rest.php index 154ef6f6..dabff770 100644 --- a/core/helpers/rest.php +++ b/core/helpers/rest.php @@ -19,12 +19,41 @@ */ class REST_Core { + const OK = "200 OK"; + const CREATED = "201 Created"; + const ACCEPTED = "202 Accepted"; + const NO_CONTENT = "204 No Content"; + const PARTIAL_CONTENT = "206 Partial Content"; + const MOVED_PERMANENTLY = "301 Moved Permanently"; + const SEE_OTHER = "303 See Other"; + const NOT_MODIFIED = "304 Not Modified"; + const TEMPORARY_REDIRECT = "307 Temporary Redirect"; + const BAD_REQUEST = "400 Bad Request"; + const UNAUTHORIZED = "401 Unauthorized"; + const FORBIDDEN = "403 Forbidden"; + const NOT_FOUND = "404 Not Found"; + const METHOD_NOT_ALLOWED = "405 Method Not Allowed"; + const NOT_ACCEPTABLE = "406 Not Acceptable"; + const CONFLICT = "409 Conflict"; + const GONE = "410 Gone"; + const LENGTH_REQUIRED = "411 Length Required"; + const PRECONDITION_FAILED = "412 Precondition Failed"; + const UNSUPPORTED_MEDIA_TYPE = "415 Unsupported Media Type"; + const EXPECTATION_FAILED = "417 Expectation Failed"; + const INTERNAL_SERVER_ERROR = "500 Internal Server Error"; + const SERVICE_UNAVAILABLE = "503 Service Unavailable"; + + const XML = "application/xml"; + const ATOM = "application/atom+xml"; + const RSS = "application/rss+xml"; + const JSON = "application/json"; + const HTML = "text/html"; + /** * We're expecting to run in an environment that only supports GET/POST, so expect to tunnel * PUT and DELETE through POST. * * Returns the HTTP request method taking into consideration PUT/DELETE tunneling. - * @todo Move this to a MY_request helper? * @return string HTTP request method */ public static function request_method() { @@ -32,7 +61,7 @@ class REST_Core { return "get"; } else { $input = Input::instance(); - switch ($input->post("_method", $input->get("_method"))) { + switch (strtolower($input->post("_method", $input->get("_method")))) { case "put": return "put"; case "delete": return "delete"; default: return "post"; @@ -46,10 +75,34 @@ class REST_Core { */ public static function output_format() { // Pick a format, but let it be overridden. - $input = Input::instance(); + $input = Input::instance(); return $input->get( "_format", $input->post( "_format", request::preferred_accept( array("html", "xml", "json")))); } + + /** + * Set HTTP response code. + * @param string Use one of status code constants defined in this class. + */ + public static function http_status($status_code) { + header("HTTP 1.1 " . $status_code); + } + + /** + * Set HTTP Location header. + * @param string URL + */ + public static function http_location($url) { + header("Location: " . $url); + } + + /** + * Set HTTP Content-Type header. + * @param string content type + */ + public static function http_content_type($type) { + header("Content-Type: " . $type); + } } |