1 | <?php namespace Arcanedev\GeoLocation\Google; |
||
14 | abstract class AbstractResponse implements Arrayable, Jsonable, JsonSerializable |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Properties |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | * The response's data. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $data = []; |
||
27 | |||
28 | /* ----------------------------------------------------------------- |
||
29 | | Constructor |
||
30 | | ----------------------------------------------------------------- |
||
31 | */ |
||
32 | |||
33 | /** |
||
34 | * AbstractResponse constructor. |
||
35 | * |
||
36 | * @param array $data |
||
37 | */ |
||
38 | public function __construct(array $data = []) |
||
42 | |||
43 | /* ----------------------------------------------------------------- |
||
44 | | Getters & Setters |
||
45 | | ----------------------------------------------------------------- |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * Get the raw response. |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | public function getRaw() |
||
57 | |||
58 | /* ----------------------------------------------------------------- |
||
59 | | Main Methods |
||
60 | | ----------------------------------------------------------------- |
||
61 | */ |
||
62 | |||
63 | /** |
||
64 | * Get a data with a given key. |
||
65 | * |
||
66 | * @param string $key |
||
67 | * @param mixed|null $default |
||
68 | * |
||
69 | * @return mixed |
||
70 | */ |
||
71 | public function get($key, $default = null) |
||
75 | |||
76 | /** |
||
77 | * Check if the response's status is OK. |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | public function isOk() |
||
85 | |||
86 | /** |
||
87 | * Convert the object to its JSON representation. |
||
88 | * |
||
89 | * @param int $options |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | public function toJson($options = 0) |
||
97 | |||
98 | /** |
||
99 | * Convert the object into something JSON serializable. |
||
100 | * |
||
101 | * @return array |
||
102 | */ |
||
103 | public function jsonSerialize() |
||
107 | } |
||
108 |