1
0

json.php 641 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class JSON {
  3. public static function header() {
  4. header("Content-Type: application/json");
  5. }
  6. public static function success($array=array()) {
  7. $flags = PRODUCTION ? 0 : JSON_PRETTY_PRINT;
  8. $output = array(
  9. "success" => true,
  10. );
  11. $output = array_merge($output, $array);
  12. die(json_encode($output, $flags));
  13. }
  14. public static function fail($array = []) {
  15. $flags = PRODUCTION ? 0 : JSON_PRETTY_PRINT;
  16. $output = array(
  17. "success" => false
  18. );
  19. if(is_string($array)) {
  20. $array = [
  21. "message" => $array,
  22. ];
  23. }
  24. $output = array_merge($output, $array);
  25. die(json_encode($output, $flags));
  26. }
  27. }
  28. ?>