1 | <?php namespace Arcanedev\GeoIP; |
||
32 | class Location implements ArrayAccess, Arrayable, Jsonable |
||
33 | { |
||
34 | /* ------------------------------------------------------------------------------------------------ |
||
35 | | Properties |
||
36 | | ------------------------------------------------------------------------------------------------ |
||
37 | */ |
||
38 | /** |
||
39 | * The location's attributes |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $attributes = []; |
||
44 | |||
45 | /* ------------------------------------------------------------------------------------------------ |
||
46 | | Constructor |
||
47 | | ------------------------------------------------------------------------------------------------ |
||
48 | */ |
||
49 | /** |
||
50 | * Create a new location instance. |
||
51 | * |
||
52 | * @param array $attributes |
||
53 | */ |
||
54 | 30 | public function __construct(array $attributes = []) |
|
58 | |||
59 | /* ------------------------------------------------------------------------------------------------ |
||
60 | | Getters & Setters |
||
61 | | ------------------------------------------------------------------------------------------------ |
||
62 | */ |
||
63 | /** |
||
64 | * Get all attributes. |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | 30 | public function attributes() |
|
72 | |||
73 | /** |
||
74 | * Get an attribute from the $attributes array. |
||
75 | * |
||
76 | * @param string $key |
||
77 | * |
||
78 | * @return mixed |
||
79 | */ |
||
80 | 30 | public function getAttribute($key) |
|
88 | |||
89 | /** |
||
90 | * Set a given attribute on the location. |
||
91 | * |
||
92 | * @param string $key |
||
93 | * @param mixed $value |
||
94 | * |
||
95 | * @return $this |
||
96 | */ |
||
97 | 6 | public function setAttribute($key, $value) |
|
103 | |||
104 | /** |
||
105 | * Return the display name of the location. |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | 30 | public function getDisplayNameAttribute() |
|
113 | |||
114 | /** |
||
115 | * Is the location the default. |
||
116 | * |
||
117 | * @param mixed $value |
||
118 | * |
||
119 | * @return mixed |
||
120 | */ |
||
121 | 30 | public function getDefaultAttribute($value) |
|
125 | |||
126 | /** |
||
127 | * Get the instance as an array. |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | 30 | public function toArray() |
|
135 | |||
136 | /** |
||
137 | * Convert the object to its JSON representation. |
||
138 | * |
||
139 | * @param int $options |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | public function toJson($options = 0) |
||
147 | |||
148 | /* ------------------------------------------------------------------------------------------------ |
||
149 | | Check Functions |
||
150 | | ------------------------------------------------------------------------------------------------ |
||
151 | */ |
||
152 | /** |
||
153 | * Determine if the location is for the same IP address. |
||
154 | * |
||
155 | * @param string $ip |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function same($ip) |
||
163 | |||
164 | /* ------------------------------------------------------------------------------------------------ |
||
165 | | Other Functions |
||
166 | | ------------------------------------------------------------------------------------------------ |
||
167 | */ |
||
168 | /** |
||
169 | * Determine if the given attribute exists. |
||
170 | * |
||
171 | * @param mixed $offset |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function offsetExists($offset) |
||
179 | |||
180 | /** |
||
181 | * Get the value for a given offset. |
||
182 | * |
||
183 | * @param string $offset |
||
184 | * |
||
185 | * @return mixed |
||
186 | */ |
||
187 | public function offsetGet($offset) |
||
191 | |||
192 | /** |
||
193 | * Set the value for a given offset. |
||
194 | * |
||
195 | * @param string $offset |
||
196 | * @param mixed $value |
||
197 | */ |
||
198 | public function offsetSet($offset, $value) |
||
202 | |||
203 | /** |
||
204 | * Get the location's attribute |
||
205 | * |
||
206 | * @param string $key |
||
207 | * |
||
208 | * @return mixed |
||
209 | */ |
||
210 | 30 | public function __get($key) |
|
214 | |||
215 | /** |
||
216 | * Set the location's attribute |
||
217 | * |
||
218 | * @param string $key |
||
219 | * @param mixed $value |
||
220 | */ |
||
221 | public function __set($key, $value) |
||
225 | |||
226 | /** |
||
227 | * Check if the location's attribute is set |
||
228 | * |
||
229 | * @param string $key |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | public function __isset($key) |
||
237 | |||
238 | /** |
||
239 | * Unset the value for a given offset. |
||
240 | * |
||
241 | * @param string $offset |
||
242 | */ |
||
243 | public function offsetUnset($offset) |
||
247 | |||
248 | /** |
||
249 | * Unset an attribute on the location. |
||
250 | * |
||
251 | * @param string $key |
||
252 | */ |
||
253 | public function __unset($key) |
||
257 | } |
||
258 |