You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
775 B

  1. <?php
  2. namespace App\Libs;
  3. class SSDB_Response
  4. {
  5. public $cmd;
  6. public $code;
  7. public $data = null;
  8. public $message;
  9. function __construct($code='ok', $data_or_message=null){
  10. $this->code = $code;
  11. if($code == 'ok'){
  12. $this->data = $data_or_message;
  13. }else{
  14. $this->message = $data_or_message;
  15. }
  16. }
  17. function __toString(){
  18. if($this->code == 'ok'){
  19. $s = $this->data === null? '' : json_encode($this->data);
  20. }else{
  21. $s = $this->message;
  22. }
  23. return sprintf('%-13s %12s %s', $this->cmd, $this->code, $s);
  24. }
  25. function ok(){
  26. return $this->code == 'ok';
  27. }
  28. function not_found(){
  29. return $this->code == 'not_found';
  30. }
  31. }