1
0

json.php 676 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. self::header();
  8. $flags = PRODUCTION ? 0 : JSON_PRETTY_PRINT;
  9. $output = array(
  10. "success" => true,
  11. );
  12. $output = array_merge($output, $array);
  13. die(json_encode($output, $flags));
  14. }
  15. public static function fail($array = []) {
  16. self::header();
  17. $flags = PRODUCTION ? 0 : JSON_PRETTY_PRINT;
  18. $output = array(
  19. "success" => false
  20. );
  21. if(is_string($array)) {
  22. $array = [
  23. "message" => $array,
  24. ];
  25. }
  26. $output = array_merge($output, $array);
  27. die(json_encode($output, $flags));
  28. }
  29. }