1
0

Json.php 599 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App;
  3. class Json {
  4. public static function header(): void {
  5. header("Content-Type: application/json");
  6. }
  7. public static function success(array $data = [], int $response_code = 200): void {
  8. self::header();
  9. $output = array_merge($data, ["success" => true]);
  10. http_response_code($response_code);
  11. echo json_encode($output);
  12. exit(0);
  13. }
  14. public static function fail(?string $message = null, int $response_code = 400): void {
  15. self::header();
  16. http_response_code($response_code);
  17. echo json_encode([
  18. "success" => false,
  19. "message" => $message
  20. ]);
  21. exit(0);
  22. }
  23. }