= 400 || $isFailurePayload) { TaskCertLogger::warning('JSON response with error status', [ 'status_code' => $statusCode, 'request_method' => (string) ($_SERVER['REQUEST_METHOD'] ?? ''), 'request_uri' => (string) ($_SERVER['REQUEST_URI'] ?? ''), 'error' => (string) ($payload['error'] ?? ''), ]); } http_response_code($statusCode); header('Content-Type: application/json; charset=utf-8'); echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); if ($terminate) { exit; } } public static function redirect(string $url, int $statusCode = 302): void { http_response_code($statusCode); header('Location: ' . $url); exit; } public static function error(string $message, int $statusCode = 400, bool $asJson = true): void { TaskCertLogger::warning('HTTP error response', [ 'status_code' => $statusCode, 'request_method' => (string) ($_SERVER['REQUEST_METHOD'] ?? ''), 'request_uri' => (string) ($_SERVER['REQUEST_URI'] ?? ''), 'as_json' => $asJson ? 1 : 0, 'message' => $message, ]); if ($asJson) { self::json([ 'success' => false, 'error' => $message, ], $statusCode, true); } http_response_code($statusCode); echo htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); exit; } }