1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ipGeolocation; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This class provides information about user's location based on ip address |
7
|
|
|
* |
8
|
|
|
* PHP version 7 |
9
|
|
|
* |
10
|
|
|
* @author yasir khurshid <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Location |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Status of request |
16
|
|
|
* |
17
|
|
|
* @var bool |
18
|
|
|
*/ |
19
|
|
|
private $status; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Information message |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $message; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* City name of the user |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $city; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Country name of the user |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $country; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Country code of the user |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $countryCode; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Latitude of the user |
51
|
|
|
* |
52
|
|
|
* @var float |
53
|
|
|
*/ |
54
|
|
|
private $latitude; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Longitude of the user |
58
|
|
|
* |
59
|
|
|
* @var float |
60
|
|
|
*/ |
61
|
|
|
private $longitude; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Region Code of the user |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
private $regionCode; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Region name of the user |
72
|
|
|
* |
73
|
|
|
* @var string |
74
|
|
|
*/ |
75
|
|
|
private $regionName; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Time zone of the user |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
private $timezone; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Postal code of the user |
86
|
|
|
* |
87
|
|
|
* @var int |
88
|
|
|
*/ |
89
|
|
|
private $postalCode; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Return status |
93
|
|
|
* |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
5 |
|
public function getStatus(): bool |
97
|
|
|
{ |
98
|
5 |
|
return $this->status; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Set status |
103
|
|
|
* |
104
|
|
|
* @param bool $status Status |
105
|
|
|
* |
106
|
|
|
* @return Location |
107
|
|
|
*/ |
108
|
5 |
|
public function setStatus(bool $status) |
109
|
|
|
{ |
110
|
5 |
|
$this->status = $status; |
111
|
|
|
|
112
|
5 |
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Return messahe |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
4 |
|
public function getMessage(): string |
121
|
|
|
{ |
122
|
4 |
|
return $this->message; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set message |
127
|
|
|
* |
128
|
|
|
* @param string $message Message |
129
|
|
|
* |
130
|
|
|
* @return Location |
131
|
|
|
*/ |
132
|
5 |
|
public function setMessage(?string $message): Location |
133
|
|
|
{ |
134
|
5 |
|
$this->message = $message; |
135
|
|
|
|
136
|
5 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Return city name |
141
|
|
|
* |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
1 |
|
public function getCity(): string |
145
|
|
|
{ |
146
|
1 |
|
return $this->city; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Set city name |
151
|
|
|
* |
152
|
|
|
* @param string $city City name |
153
|
|
|
* |
154
|
|
|
* @return Location |
155
|
|
|
*/ |
156
|
3 |
|
public function setCity(?string $city): Location |
157
|
|
|
{ |
158
|
3 |
|
$this->city = $city; |
159
|
|
|
|
160
|
3 |
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Return coutry name |
165
|
|
|
* |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
1 |
|
public function getCountry(): string |
169
|
|
|
{ |
170
|
1 |
|
return $this->country; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Set country name |
175
|
|
|
* |
176
|
|
|
* @param string $country Country name |
177
|
|
|
* |
178
|
|
|
* @return Location |
179
|
|
|
*/ |
180
|
3 |
|
public function setCountry(?string $country): Location |
181
|
|
|
{ |
182
|
3 |
|
$this->country = $country; |
183
|
|
|
|
184
|
3 |
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Return coutry code |
189
|
|
|
* |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
1 |
|
public function getCountryCode(): string |
193
|
|
|
{ |
194
|
1 |
|
return $this->countryCode; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Set country code |
199
|
|
|
* |
200
|
|
|
* @param string $countryCode Country code |
201
|
|
|
* |
202
|
|
|
* @return Location |
203
|
|
|
*/ |
204
|
3 |
|
public function setCountryCode(?string $countryCode): Location |
205
|
|
|
{ |
206
|
3 |
|
$this->countryCode = $countryCode; |
207
|
|
|
|
208
|
3 |
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Return latitude |
213
|
|
|
* |
214
|
|
|
* @return float |
215
|
|
|
*/ |
216
|
1 |
|
public function getLatitude(): float |
217
|
|
|
{ |
218
|
1 |
|
return $this->latitude; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Set latitude |
223
|
|
|
* |
224
|
|
|
* @param string $latitude |
225
|
|
|
* |
226
|
|
|
* @return Location |
227
|
|
|
*/ |
228
|
3 |
|
public function setLatitude(?string $latitude): Location |
229
|
|
|
{ |
230
|
3 |
|
$this->latitude = (float) $latitude; |
231
|
|
|
|
232
|
3 |
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Return longitude |
237
|
|
|
* |
238
|
|
|
* @return float |
239
|
|
|
*/ |
240
|
1 |
|
public function getLongitude(): float |
241
|
|
|
{ |
242
|
1 |
|
return $this->longitude; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Set longitude |
247
|
|
|
* |
248
|
|
|
* @param string $longitude Longitude |
249
|
|
|
* |
250
|
|
|
* @return Location |
251
|
|
|
*/ |
252
|
3 |
|
public function setLongitude(?string $longitude): Location |
253
|
|
|
{ |
254
|
3 |
|
$this->longitude = (float) $longitude; |
255
|
|
|
|
256
|
3 |
|
return $this; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Return region code |
261
|
|
|
* |
262
|
|
|
* @return string |
263
|
|
|
*/ |
264
|
1 |
|
public function getRegionCode(): string |
265
|
|
|
{ |
266
|
1 |
|
return $this->regionCode; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Set region code |
271
|
|
|
* |
272
|
|
|
* @param string $regionCode Region code |
273
|
|
|
* |
274
|
|
|
* @return Location |
275
|
|
|
*/ |
276
|
3 |
|
public function setRegionCode(?string $regionCode): Location |
277
|
|
|
{ |
278
|
3 |
|
$this->regionCode = $regionCode; |
279
|
|
|
|
280
|
3 |
|
return $this; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Retrun region name |
285
|
|
|
* |
286
|
|
|
* @return string |
287
|
|
|
*/ |
288
|
1 |
|
public function getRegionName(): string |
289
|
|
|
{ |
290
|
1 |
|
return $this->regionName; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Set region name |
295
|
|
|
* |
296
|
|
|
* @param string $regionName Region name |
297
|
|
|
* |
298
|
|
|
* @return Location |
299
|
|
|
*/ |
300
|
3 |
|
public function setRegionName(?string $regionName): Location |
301
|
|
|
{ |
302
|
3 |
|
$this->regionName = $regionName; |
303
|
|
|
|
304
|
3 |
|
return $this; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Return timezone |
309
|
|
|
* |
310
|
|
|
* @return string |
311
|
|
|
*/ |
312
|
1 |
|
public function getTimezone(): string |
313
|
|
|
{ |
314
|
1 |
|
return $this->timezone; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Set timezone |
319
|
|
|
* |
320
|
|
|
* @param string $timezone |
321
|
|
|
* |
322
|
|
|
* @return Location |
323
|
|
|
*/ |
324
|
3 |
|
public function setTimezone(?string $timezone): Location |
325
|
|
|
{ |
326
|
3 |
|
$this->timezone = $timezone; |
327
|
|
|
|
328
|
3 |
|
return $this; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Return postal code |
333
|
|
|
* |
334
|
|
|
* @return int |
335
|
|
|
*/ |
336
|
1 |
|
public function getPostalCode(): int |
337
|
|
|
{ |
338
|
1 |
|
return $this->postalCode; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Set postal code |
343
|
|
|
* |
344
|
|
|
* @param string $postalCode Postal code |
345
|
|
|
* |
346
|
|
|
* @return Location |
347
|
|
|
*/ |
348
|
3 |
|
public function setPostalCode(?string $postalCode): Location |
349
|
|
|
{ |
350
|
3 |
|
$this->postalCode = (int) $postalCode; |
351
|
|
|
|
352
|
3 |
|
return $this; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Return currency Iso code |
357
|
|
|
* |
358
|
|
|
* @return string |
359
|
|
|
*/ |
360
|
1 |
|
public function getCurrencyIso(): string |
361
|
|
|
{ |
362
|
1 |
|
return (new Currency())->getCurrencyIso($this->countryCode); |
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
|