update api and ajax handling and response

This commit is contained in:
envoyr
2022-02-20 11:38:08 +01:00
parent d5e53cc7db
commit 424a00b39e
65 changed files with 881 additions and 2736 deletions

View File

@@ -243,7 +243,7 @@ abstract class ApiCommand extends ApiParameter
*/
protected function getUserDetail($detail = null)
{
return (isset($this->user_data[$detail]) ? $this->user_data[$detail] : null);
return ($this->user_data[$detail] ?? null);
}
/**
@@ -463,32 +463,16 @@ abstract class ApiCommand extends ApiParameter
return json_decode($json_result, true)['data'];
}
/**
* return api-compatible response in JSON format and send corresponding http-header
*
* @param int $status
* @param string $status_message
* @param mixed $data
*
* @return string json-encoded response message
*/
protected function response($status, $status_message, $data = null)
/**
* return api-compatible response in JSON format and send corresponding http-header
*
* @param mixed $data
* @param int $response_code
* @return string json-encoded response message
*/
protected function response($data = null, int $response_code = 200)
{
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);
return $json_response;
return \Froxlor\Api\Response::jsonDataResponse($data, $response_code);
}
/**