Skip to content

Commit ce9b51e

Browse files
author
Marius Burkard
committed
- changed json handler for REST api
1 parent c2560ac commit ce9b51e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

interface/lib/classes/json_handler.inc.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,11 @@ public function run() {
8888
$keys = array_keys($_GET);
8989
$method = reset($keys);
9090
$params = array();
91-
92-
if(is_array($_POST)) {
93-
foreach($_POST as $key => $val) {
94-
$tmp = json_decode($val, true);
95-
if(!$tmp) $params[] = $val;
96-
else $params[] = (array)$tmp;
97-
}
98-
}
99-
91+
92+
$raw = file_get_contents("php://input");
93+
$json = json_decode($raw, true);
94+
if(!is_array($json)) $this->_return_json('invalid_data', 'The JSON data sent to the api is invalid');
95+
10096
if(array_key_exists($method, $this->methods) == false) {
10197
$this->_return_json('invalid_method', 'Method ' . $method . ' does not exist');
10298
}
@@ -109,7 +105,14 @@ public function run() {
109105
if(method_exists($this->classes[$class_name], $method) == false) {
110106
$this->_return_json('invalid_method', 'Method ' . $method . ' does not exist in the class it was expected (' . $class_name . ')');
111107
}
112-
108+
109+
$methObj = new ReflectionMethod($this->classes[$class_name], $method);
110+
foreach($methObj->getParameters() as $param) {
111+
$pname = $param->name;
112+
if(isset($json[$pname])) $params[] = $json[$pname];
113+
else $params[] = null;
114+
}
115+
113116
try {
114117
$this->_return_json('ok', '', call_user_func_array(array($this->classes[$class_name], $method), $params));
115118
} catch(SoapFault $e) {

0 commit comments

Comments
 (0)