Response.php
892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 1/27/15
* Time: 10:30 PM
*/
namespace Hood\Cache\Ssdb;
class Response
{
public $cmd;
public $code;
public $data = null;
public $message;
function __construct($code = 'ok', $data_or_message = null)
{
$this->code = $code;
if ($code == 'ok') {
$this->data = $data_or_message;
} else {
$this->message = $data_or_message;
}
}
function __toString()
{
if ($this->code == 'ok') {
$s = $this->data === null ? '' : json_encode($this->data);
} else {
$s = $this->message;
}
return sprintf('%-13s %12s %s', $this->cmd, $this->code, $s);
}
function ok()
{
return $this->code == 'ok';
}
function not_found()
{
return $this->code == 'not_found';
}
}