3 require_once dirname(__FILE__) .
'/controller.php';
33 'application/json' => array(
'RestController',
'parseJSON'),
34 'application/xml' => array(
'RestController',
'parseXML'),
35 'text/xml' => array(
'RestController',
'parseXML'),
36 'text/csv' => array(
'RestController',
'parseCSV'),
37 'application/x-www-form-urlencoded' => array(
'RestController',
'parseForm'),
52 'application/json' =>
'json',
53 'application/xml' =>
'xml',
59 parent::__construct($module, $controller, $action,
$parameters);
69 $this->_fInput = isset($_SERVER[
"CONTENT_TYPE"]) ? $_SERVER[
"CONTENT_TYPE"] :
'';
71 $accept = self::accept();
72 $keys = array_keys($this->_outputType);
73 foreach ($accept as $key => $a) {
74 if (in_array($key, $keys)) {
75 $this->_fOutput = $this->_outputType[$key];
90 $rewrite =
"{$method}_{$action}";
92 $this->action_name = $rewrite;
93 } elseif ($action ==
'index' && $method !=
'post') {
94 $this->action_name =
'getAll';
96 $this->action_name = $method;
97 $this->parameters = ($action ==
'index') ? $this->parameters : array($action) +
$this->parameters;
107 if (method_exists($this, $name)) {
108 $reflection =
new ReflectionMethod($this, $name);
109 return $reflection->isPublic();
119 $input = file_get_contents(
'php://input');
122 if (isset($this->_inputType[$format]) && is_callable($this->_inputType[$format])) {
123 $result = call_user_func($this->_inputType[$format], $input);
138 100 =>
'100 Continue',
139 101 =>
'101 Switching Protocols',
142 201 =>
'201 Created',
143 202 =>
'202 Accepted',
144 203 =>
'203 Non-Authoritative Information',
145 204 =>
'204 No Content',
146 205 =>
'205 Reset Content',
147 206 =>
'206 Partial Content',
149 300 =>
'300 Multiple Choices',
150 301 =>
'301 Moved Permanently',
152 303 =>
'303 See Other',
153 304 =>
'304 Not Modified',
154 305 =>
'305 Use Proxy',
155 306 =>
'306 (Unused)',
156 307 =>
'307 Temporary Redirect',
158 400 =>
'400 Bad Request',
159 401 =>
'401 Unauthorized',
160 402 =>
'402 Payment Required',
161 403 =>
'403 Forbidden',
162 404 =>
'404 Not Found',
163 405 =>
'405 Method Not Allowed',
164 406 =>
'406 Not Acceptable',
165 407 =>
'407 Proxy Authentication Required',
166 408 =>
'408 Request Timeout',
167 409 =>
'409 Conflict',
169 411 =>
'411 Length Required',
170 412 =>
'412 Precondition Failed',
171 413 =>
'413 Request Entity Too Large',
172 414 =>
'414 Request-URI Too Long',
173 415 =>
'415 Unsupported Media Type',
174 416 =>
'416 Requested Range Not Satisfiable',
175 417 =>
'417 Expectation Failed',
176 422 =>
'422 Unprocessable Entity',
179 500 =>
'500 Internal Server Error',
180 501 =>
'501 Not Implemented',
181 502 =>
'502 Bad Gateway',
182 503 =>
'503 Service Unavailable',
183 504 =>
'504 Gateway Timeout',
184 505 =>
'505 HTTP Version Not Supported'
186 if (isset($code[$num])) {
187 header(sprintf(
'HTTP/1.1 %d %s', $num, $code[$num]));
200 $accept = explode(
',', strtolower(str_replace(
' ',
'', $_SERVER[
'HTTP_ACCEPT'])));
201 foreach ($accept as $a) {
203 if (strpos($a,
';q=')) {
205 list($a, $q) = explode(
';q=', $a);
222 if (function_exists(
'json_decode')) {
223 $result = json_decode($input,
true);
240 if (class_exists(
'SimpleXMLElement')) {
242 return new SimpleXMLElement($input);
243 }
catch (Exception $e) {
260 $temp = fopen(
'php://memory',
'rw');
261 fwrite($temp, $input);
264 while (($data = fgetcsv($temp)) !==
false) {
278 parse_str($input, $vars);