'Command not specified']); return; } try { $result = $broker->{$_REQUEST['command']}(); } catch (Exception $e) { $status = $e->getCode() ?: 500; $result = ['error' => $e->getMessage()]; } // JSONP if (!empty($_GET['callback'])) { if (!isset($result)) $result = null; if (!isset($status)) $status = isset($result) ? 200 : 204; header('Content-Type: application/javascript'); echo $_GET['callback'] . '(' . json_encode($result) . ', ' . $status . ')'; return; } // REST if (!$result) { http_response_code(204); } else { http_response_code(isset($status) ? $status : 200); header("Content-Type: application/json"); echo json_encode($result); }