35 private static $code = array(
38 401 =>
'Unauthorized',
40 405 =>
'Method Not Allowed'
45 private static $_outputFormat = array(
'json',
'text',
'html',
'xml',
'cvs',
'php');
49 private static $_inputFormat = array(
'json',
'plain',
'x-www-form-urlencoded');
53 private static $_method = null;
57 private static $_oFormat = null;
61 private static $_iFormat = null;
68 static public function accept($accept)
70 self::$_outputFormat = is_array($accept) ? $accept : explode(
',', $accept);
80 $content = isset($_SERVER[
'CONTENT_TYPE']) ? $_SERVER[
'CONTENT_TYPE'] :
'text/html';
84 self::$_iFormat = str_replace(array(
'text/',
'application/'),
'', $content);
87 self::$_method = strtolower($_SERVER[
'REQUEST_METHOD']);
88 $format = explode(
',', $_SERVER[
'HTTP_ACCEPT']);
89 while (self::$_oFormat = array_shift($format)) {
90 self::$_oFormat = str_replace(array(
'text/',
'application/'),
'', self::$_oFormat);
91 if (in_array(self::$_oFormat, self::$_outputFormat)) {
99 if (self::$_oFormat == null) {
109 if ( is_numeric($controller->action_name) ){
110 $controller->parameters = array($controller->action_name) +
Rest::param();
119 $controller->action_name = self::$_method;
120 $controller->limit_params = FALSE;
121 $controller->data = array();
131 $input = file_get_contents(
'php://input');
132 if (strncmp(self::$_iFormat,
'json', 4) == 0) {
133 return json_decode($input,
true);
135 parse_str($input, $output);