1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace GeoIp2\Record;
|
|
|
6 |
|
|
|
7 |
/**
|
|
|
8 |
* Contains data for the location record associated with an IP address.
|
|
|
9 |
*
|
|
|
10 |
* This record is returned by all location services and databases besides
|
|
|
11 |
* Country.
|
|
|
12 |
*/
|
|
|
13 |
class Location implements \JsonSerializable
|
|
|
14 |
{
|
|
|
15 |
/**
|
|
|
16 |
* @var int|null The average income in US dollars
|
|
|
17 |
* associated with the requested IP address. This attribute is only available
|
|
|
18 |
* from the Insights service.
|
|
|
19 |
*/
|
|
|
20 |
public readonly ?int $averageIncome;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* @var int|null The approximate accuracy radius in
|
|
|
24 |
* kilometers around the latitude and longitude for the IP address. This is
|
|
|
25 |
* the radius where we have a 67% confidence that the device using the IP
|
|
|
26 |
* address resides within the circle centered at the latitude and longitude
|
|
|
27 |
* with the provided radius.
|
|
|
28 |
*/
|
|
|
29 |
public readonly ?int $accuracyRadius;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* @var float|null The approximate latitude of the location
|
|
|
33 |
* associated with the IP address. This value is not precise and should not be
|
|
|
34 |
* used to identify a particular address or household.
|
|
|
35 |
*/
|
|
|
36 |
public readonly ?float $latitude;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* @var float|null The approximate longitude of the location
|
|
|
40 |
* associated with the IP address. This value is not precise and should not be
|
|
|
41 |
* used to identify a particular address or household.
|
|
|
42 |
*/
|
|
|
43 |
public readonly ?float $longitude;
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* @var int|null The metro code of the location if the location
|
|
|
47 |
* is in the US. MaxMind returns the same metro codes as the
|
|
|
48 |
* Google AdWords API. See
|
|
|
49 |
* https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions.
|
|
|
50 |
*/
|
|
|
51 |
public readonly ?int $metroCode;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* @var int|null The estimated population per square
|
|
|
55 |
* kilometer associated with the IP address. This attribute is only available
|
|
|
56 |
* from the Insights service.
|
|
|
57 |
*/
|
|
|
58 |
public readonly ?int $populationDensity;
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* @var string|null The time zone associated with location, as
|
|
|
62 |
* specified by the IANA Time Zone Database, e.g., "America/New_York". See
|
|
|
63 |
* https://www.iana.org/time-zones.
|
|
|
64 |
*/
|
|
|
65 |
public readonly ?string $timeZone;
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* @ignore
|
|
|
69 |
*
|
|
|
70 |
* @param array<string, mixed> $record
|
|
|
71 |
*/
|
|
|
72 |
public function __construct(array $record)
|
|
|
73 |
{
|
|
|
74 |
$this->averageIncome = $record['average_income'] ?? null;
|
|
|
75 |
$this->accuracyRadius = $record['accuracy_radius'] ?? null;
|
|
|
76 |
$this->latitude = $record['latitude'] ?? null;
|
|
|
77 |
$this->longitude = $record['longitude'] ?? null;
|
|
|
78 |
$this->metroCode = $record['metro_code'] ?? null;
|
|
|
79 |
$this->populationDensity = $record['population_density'] ?? null;
|
|
|
80 |
$this->timeZone = $record['time_zone'] ?? null;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* @return array<string, mixed>
|
|
|
85 |
*/
|
|
|
86 |
public function jsonSerialize(): array
|
|
|
87 |
{
|
|
|
88 |
$js = [];
|
|
|
89 |
if ($this->averageIncome !== null) {
|
|
|
90 |
$js['average_income'] = $this->averageIncome;
|
|
|
91 |
}
|
|
|
92 |
if ($this->accuracyRadius !== null) {
|
|
|
93 |
$js['accuracy_radius'] = $this->accuracyRadius;
|
|
|
94 |
}
|
|
|
95 |
if ($this->latitude !== null) {
|
|
|
96 |
$js['latitude'] = $this->latitude;
|
|
|
97 |
}
|
|
|
98 |
if ($this->longitude !== null) {
|
|
|
99 |
$js['longitude'] = $this->longitude;
|
|
|
100 |
}
|
|
|
101 |
if ($this->metroCode !== null) {
|
|
|
102 |
$js['metro_code'] = $this->metroCode;
|
|
|
103 |
}
|
|
|
104 |
if ($this->populationDensity !== null) {
|
|
|
105 |
$js['population_density'] = $this->populationDensity;
|
|
|
106 |
}
|
|
|
107 |
if ($this->timeZone !== null) {
|
|
|
108 |
$js['time_zone'] = $this->timeZone;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
return $js;
|
|
|
112 |
}
|
|
|
113 |
}
|