Files
musadaq-saas/app/bootstrap/response.php
2026-05-03 17:32:57 +03:00

26 lines
693 B
PHP

<?php
/**
* Standardized JSON Responses
*/
function json_response(bool $success, $data = null, ?string $message = null, int $code = 200) {
header('Content-Type: application/json; charset=utf-8');
http_response_code($code);
echo json_encode([
'success' => $success,
'data' => $data,
'message' => $message,
'timestamp' => date('c')
], JSON_UNESCAPED_UNICODE);
exit;
}
function json_error(string $message, int $code = 400, $errors = null) {
json_response(false, $errors, $message, $code);
}
function json_success($data = null, ?string $message = 'Success', int $code = 200) {
json_response(true, $data, $message, $code);
}