class-json-response.php 843 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class Booked_WC_Response {
  3. protected $message = array();
  4. protected $status = 'error';
  5. protected $misc = array();
  6. public function __construct() {
  7. }
  8. public function erase_message() {
  9. $this->message = array();
  10. return $this;
  11. }
  12. public function add_message( $message='' ) {
  13. if ( !$message ) {
  14. return $this;
  15. }
  16. $this->message[] = $message;
  17. return $this;
  18. }
  19. public function set_status( $status=false ) {
  20. $this->status = $status===false ? 'error' : 'success';
  21. return $this;
  22. }
  23. public function create() {
  24. $output = array_merge(array(
  25. 'status' => $this->status,
  26. 'messages' => $this->message
  27. ), $this->misc);
  28. exit(json_encode($output));
  29. }
  30. public function add_misc($property, $value) {
  31. $this->misc[$property] = $value;
  32. return $this;
  33. }
  34. }