1 | <?php namespace Arcanedev\GeoLocation\Google; |
||
15 | abstract class AbstractResponse implements Arrayable, Jsonable, JsonSerializable |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Constants |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | const STATUS_OK = 'OK'; |
||
23 | const STATUS_ZERO_RESULTS = 'ZERO_RESULTS'; |
||
24 | |||
25 | /* ----------------------------------------------------------------- |
||
26 | | Traits |
||
27 | | ----------------------------------------------------------------- |
||
28 | */ |
||
29 | |||
30 | use CanBeJsonable; |
||
31 | |||
32 | /* ----------------------------------------------------------------- |
||
33 | | Properties |
||
34 | | ----------------------------------------------------------------- |
||
35 | */ |
||
36 | |||
37 | /** |
||
38 | * The response's data. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $data = []; |
||
43 | |||
44 | /* ----------------------------------------------------------------- |
||
45 | | Constructor |
||
46 | | ----------------------------------------------------------------- |
||
47 | */ |
||
48 | |||
49 | /** |
||
50 | * AbstractResponse constructor. |
||
51 | * |
||
52 | * @param array $data |
||
53 | */ |
||
54 | 111 | public function __construct(array $data = []) |
|
58 | |||
59 | /* ----------------------------------------------------------------- |
||
60 | | Getters & Setters |
||
61 | | ----------------------------------------------------------------- |
||
62 | */ |
||
63 | |||
64 | /** |
||
65 | * Get the raw response. |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | 105 | public function getRaw() |
|
73 | |||
74 | /** |
||
75 | * Get the status. |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 42 | public function getStatus() |
|
83 | |||
84 | /* ----------------------------------------------------------------- |
||
85 | | Main Methods |
||
86 | | ----------------------------------------------------------------- |
||
87 | */ |
||
88 | |||
89 | /** |
||
90 | * Get a data with a given key. |
||
91 | * |
||
92 | * @param string $key |
||
93 | * @param mixed|null $default |
||
94 | * |
||
95 | * @return mixed |
||
96 | */ |
||
97 | 99 | public function get($key, $default = null) |
|
101 | |||
102 | /** |
||
103 | * Check if the response's status is OK. |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | 42 | public function isOk() |
|
114 | } |
||
115 |