1 | <?php namespace Arcanedev\GeoIP; |
||
33 | class Location implements ArrayAccess, Arrayable, Jsonable, JsonSerializable |
||
34 | { |
||
35 | /* ----------------------------------------------------------------- |
||
36 | | Properties |
||
37 | | ----------------------------------------------------------------- |
||
38 | */ |
||
39 | |||
40 | /** |
||
41 | * The location's attributes |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $attributes = []; |
||
46 | |||
47 | /* ----------------------------------------------------------------- |
||
48 | | Constructor |
||
49 | | ----------------------------------------------------------------- |
||
50 | */ |
||
51 | |||
52 | /** |
||
53 | * Create a new location instance. |
||
54 | * |
||
55 | * @param array $attributes |
||
56 | */ |
||
57 | 15 | public function __construct(array $attributes = []) |
|
61 | |||
62 | /* ----------------------------------------------------------------- |
||
63 | | Getters & Setters |
||
64 | | ----------------------------------------------------------------- |
||
65 | */ |
||
66 | |||
67 | /** |
||
68 | * Get all attributes. |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | 15 | public function attributes() |
|
76 | |||
77 | /** |
||
78 | * Get an attribute from the location. |
||
79 | * |
||
80 | * @param string $key |
||
81 | * |
||
82 | * @return mixed |
||
83 | */ |
||
84 | 15 | public function getAttribute($key) |
|
92 | |||
93 | /** |
||
94 | * Set a given attribute on the location. |
||
95 | * |
||
96 | * @param string $key |
||
97 | * @param mixed $value |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | 3 | public function setAttribute($key, $value) |
|
107 | |||
108 | /** |
||
109 | * Return the display name of the location. |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 15 | public function getDisplayNameAttribute() |
|
117 | |||
118 | /** |
||
119 | * Is the location the default. |
||
120 | * |
||
121 | * @param mixed $value |
||
122 | * |
||
123 | * @return mixed |
||
124 | */ |
||
125 | 15 | public function getDefaultAttribute($value) |
|
129 | |||
130 | /** |
||
131 | * Get the instance as an array. |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | 15 | public function toArray() |
|
139 | |||
140 | /** |
||
141 | * Convert the object into something JSON serializable. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | public function jsonSerialize() |
||
149 | |||
150 | /** |
||
151 | * Convert the object to its JSON representation. |
||
152 | * |
||
153 | * @param int $options |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | public function toJson($options = 0) |
||
161 | |||
162 | /* ----------------------------------------------------------------- |
||
163 | | Check Methods |
||
164 | | ----------------------------------------------------------------- |
||
165 | */ |
||
166 | |||
167 | /** |
||
168 | * Determine if the location is for the same IP address. |
||
169 | * |
||
170 | * @param string $ip |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | public function same($ip) |
||
178 | |||
179 | /* ----------------------------------------------------------------- |
||
180 | | Other Methods |
||
181 | | ----------------------------------------------------------------- |
||
182 | */ |
||
183 | |||
184 | /** |
||
185 | * Determine if the given attribute exists. |
||
186 | * |
||
187 | * @param mixed $offset |
||
188 | * |
||
189 | * @return bool |
||
190 | */ |
||
191 | public function offsetExists($offset) |
||
195 | |||
196 | /** |
||
197 | * Get the value for a given offset. |
||
198 | * |
||
199 | * @param string $offset |
||
200 | * |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public function offsetGet($offset) |
||
207 | |||
208 | /** |
||
209 | * Set the value for a given offset. |
||
210 | * |
||
211 | * @param string $offset |
||
212 | * @param mixed $value |
||
213 | */ |
||
214 | public function offsetSet($offset, $value) |
||
218 | |||
219 | /** |
||
220 | * Get the location's attribute |
||
221 | * |
||
222 | * @param string $key |
||
223 | * |
||
224 | * @return mixed |
||
225 | */ |
||
226 | 15 | public function __get($key) |
|
230 | |||
231 | /** |
||
232 | * Set the location's attribute |
||
233 | * |
||
234 | * @param string $key |
||
235 | * @param mixed $value |
||
236 | */ |
||
237 | public function __set($key, $value) |
||
241 | |||
242 | /** |
||
243 | * Check if the location's attribute is set |
||
244 | * |
||
245 | * @param string $key |
||
246 | * |
||
247 | * @return bool |
||
248 | */ |
||
249 | public function __isset($key) |
||
253 | |||
254 | /** |
||
255 | * Unset the value for a given offset. |
||
256 | * |
||
257 | * @param string $offset |
||
258 | */ |
||
259 | public function offsetUnset($offset) |
||
263 | |||
264 | /** |
||
265 | * Unset an attribute on the location. |
||
266 | * |
||
267 | * @param string $key |
||
268 | */ |
||
269 | public function __unset($key) |
||
273 | } |
||
274 |