shr3dd3r
12143c148d
Добавлен .gitignore, скрыты несколько нинужных файлов, в целом продолжен запил основных частей функционала, начат микрорефакторинг (теперь концентрация индусского кода будет чуть меньше).
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php // JSON-related functions
|
|
|
|
// Includes
|
|
require_once("_errorslist.php");
|
|
|
|
|
|
|
|
// Write valid JSON data to stdout and exit
|
|
function JSON_ReturnData ($arr) {
|
|
$data = json_encode($arr);
|
|
if (!$data) {
|
|
$data = json_encode(
|
|
array(
|
|
"error" => Errors_ResolveNameByCode(E_UNS_JSONBADINP)
|
|
)
|
|
);
|
|
}
|
|
header("Content-Type: application/json; charset=utf-8");
|
|
echo $data;
|
|
exit;
|
|
}
|
|
|
|
// Return error as JSON data to stdout and exit
|
|
function JSON_ReturnError (int $code = -1, string $name = "", string $desc = "") {
|
|
if ($code === -1 && empty($name))
|
|
JSON_ReturnError(code: E_UNS_INTERNAL, desc: "cant return error without specified code or name");
|
|
else if ($code === -1)
|
|
$code = Errors_ResolveCodeByName($name);
|
|
else if (empty($name))
|
|
$name = Errors_ResolveNameByCode($code);
|
|
|
|
JSON_ReturnData(array(
|
|
"error" => $name, // Name
|
|
"error_code" => $code, // Code
|
|
"error_hum" => Errors_ResolveDescByCode($code), // Common description
|
|
"description" => $desc // Detailed decription
|
|
));
|
|
}
|
|
|
|
|
|
|
|
?>
|