2024-01-13 05:54:42 +05:30
|
|
|
<?php
|
|
|
|
// Necessary functions, types and other stuff
|
|
|
|
|
|
|
|
|
2023-11-01 00:27:17 +05:30
|
|
|
|
|
|
|
// Includes
|
2024-01-20 22:35:45 +05:30
|
|
|
if (isset($IS_FRONTEND) && $IS_FRONTEND) {
|
2023-12-20 08:38:13 +05:30
|
|
|
require_once("api/_errorslist.php");
|
|
|
|
require_once("api/_json.php");
|
|
|
|
} else {
|
|
|
|
require_once("_errorslist.php");
|
|
|
|
require_once("_json.php");
|
|
|
|
}
|
2023-11-01 00:27:17 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final class ErrorT {
|
|
|
|
private int $Code;
|
|
|
|
private string $Name;
|
|
|
|
private string $Description;
|
|
|
|
|
|
|
|
|
|
|
|
// Ctor
|
|
|
|
public function __construct(int $code = -1, string $name = "", string $desc = "") {
|
|
|
|
if ($code === -1 && empty($name))
|
|
|
|
JSON_ReturnError(code: E_UNS_INTERNAL, desc: "cant construct ErrorT without at least error code or name");
|
|
|
|
else if ($code === -1)
|
|
|
|
$code = Errors_ResolveCodeByName($name);
|
|
|
|
else if (empty($name))
|
|
|
|
$name = Errors_ResolveNameByCode($code);
|
|
|
|
|
|
|
|
$this->Code = $code;
|
|
|
|
$this->Name = $name;
|
|
|
|
$this->Description = $desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getter for error code
|
|
|
|
public function GetCode (): int {
|
|
|
|
return $this->Code;
|
|
|
|
}
|
|
|
|
// Getter for error name
|
|
|
|
public function GetName (): string {
|
|
|
|
return $this->Name;
|
|
|
|
}
|
|
|
|
// Getter for error description
|
|
|
|
public function GetDescription (): string {
|
|
|
|
return $this->Description;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stringify error
|
|
|
|
public function Stringify (): string {
|
|
|
|
if (isset($this->Description))
|
|
|
|
return "error " . $this->Name . " (" . strval($this->Code) . "): " . $this->Description;
|
|
|
|
else
|
|
|
|
return "error " . $this->Name . " (" . strval($this->Code) . ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return type of API method
|
|
|
|
final class ReturnT {
|
|
|
|
private ErrorT $ErrorObj;
|
|
|
|
private $Data;
|
|
|
|
|
|
|
|
|
|
|
|
// Ctor
|
|
|
|
public function __construct($data = null, int $err_code = 0, string $err_name = "", string $err_desc = "") {
|
|
|
|
$this->ErrorObj = new ErrorT($err_code, $err_name, $err_desc);
|
|
|
|
$this->Data = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setter/getter for data
|
|
|
|
public function SetData ($d) {
|
|
|
|
$this->Data = $d;
|
|
|
|
}
|
|
|
|
public function GetData () {
|
|
|
|
return $this->Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get string representation of error
|
|
|
|
public function GetError (): string {
|
|
|
|
return $this->ErrorObj->Stringify();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is there any error
|
|
|
|
public function IsError (): bool {
|
|
|
|
return $this->ErrorObj->GetCode() !== E_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Throw JSON error
|
|
|
|
function ThrowJSONError () {
|
|
|
|
JSON_ReturnError(
|
|
|
|
$this->ErrorObj->GetCode(),
|
|
|
|
$this->ErrorObj->GetName(),
|
|
|
|
$this->ErrorObj->Stringify()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|