Response.php 518 B

123456789101112131415161718192021222324252627
  1. <?php
  2. class Response {
  3. public static function sendJson($data) {
  4. header("Content-type: application/json");
  5. echo json_encode($data);
  6. }
  7. public static function sendPlainText($data) {
  8. header("Content-type: text/plain");
  9. if (!is_scalar($data)) throw new Exception("Wrong data type - only scalar values allowed");
  10. echo $data;
  11. }
  12. public static function sendJsonExit($data) {
  13. self::sendJson($data);
  14. exit;
  15. }
  16. public static function sendPlainTextExit($data) {
  17. self::sendPlainText($data);
  18. exit;
  19. }
  20. }