1 | <?php |
||
9 | class Response |
||
10 | { |
||
11 | private $decodedBody; |
||
12 | |||
13 | /** |
||
14 | * @param String $body |
||
15 | */ |
||
16 | public function __construct($body) |
||
20 | |||
21 | public function getText() |
||
22 | { |
||
23 | $text = $this->getDecodedBodyValue('text'); |
||
24 | |||
25 | if (!is_array($text)) { |
||
26 | return null; |
||
27 | } |
||
28 | |||
29 | return reset($text); |
||
30 | } |
||
31 | |||
32 | protected function getLang() |
||
33 | { |
||
34 | $lang = $this->getDecodedBodyValue('lang'); |
||
35 | |||
36 | if (!$lang) { |
||
37 | return false; |
||
38 | } |
||
39 | |||
40 | return explode('-', $lang); |
||
41 | } |
||
42 | |||
43 | public function getFrom() |
||
44 | { |
||
45 | if (!$lang = $this->getLang()) { |
||
46 | return null; |
||
47 | } |
||
48 | |||
49 | return reset($lang); |
||
50 | } |
||
51 | |||
52 | public function getTo() |
||
53 | { |
||
54 | if (!$lang = $this->getLang()) { |
||
55 | return null; |
||
56 | } |
||
57 | |||
58 | return end($lang); |
||
59 | } |
||
60 | |||
61 | public function getCode() |
||
65 | |||
66 | private function getDecodedBodyValue($key) |
||
67 | { |
||
68 | if (!array_key_exists($key, $this->decodedBody)) { |
||
69 | return null; |
||
74 | } |
||
75 |