| 1234567891011121314151617181920212223242526272829 |
- <?php
- namespace App;
- class Json {
- public static function header(): void {
- header("Content-Type: application/json");
- }
- public static function success(array $data = [], int $response_code = 200): void {
- self::header();
- $output = array_merge($data, ["success" => true]);
- http_response_code($response_code);
- echo json_encode($output);
- exit(0);
- }
- public static function fail(?string $message = null, int $response_code = 400): void {
- self::header();
- http_response_code($response_code);
- echo json_encode([
- "success" => false,
- "message" => $message
- ]);
- exit(0);
- }
- }
|