xss_clean($request); // validate content try { $decoded_request = stripcslashes_deep($decoded_request); $request = \Froxlor\Api\FroxlorRPC::validateRequest($decoded_request); // now actually do it $cls = "\\Froxlor\\Api\\Commands\\" . $request['command']['class']; $method = $request['command']['method']; $apiObj = new $cls($decoded_request['header'], $request['params']); // call the method with the params if any echo $apiObj->$method(); } catch (Exception $e) { json_response($e->getCode(), $e->getMessage()); } exit(); /** * output json result * * @param int $status * @param string $status_message * @param mixed $data * * @return void */ function json_response($status, $status_message = '', $data = null) { if (isset($_SERVER["SERVER_PROTOCOL"]) && ! empty($_SERVER["SERVER_PROTOCOL"])) { $resheader = $_SERVER["SERVER_PROTOCOL"] . " " . $status; if (! empty($status_message)) { $resheader .= ' ' . str_replace("\n", " ", $status_message); } header($resheader); } $response = array(); $response['status'] = $status; $response['status_message'] = $status_message; $response['data'] = $data; $json_response = json_encode($response, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); echo $json_response; exit(); } function stripcslashes_deep($value) { return is_array($value) ? array_map('stripcslashes_deep', $value) : stripcslashes($value); }