-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPResult.php
145 lines (129 loc) · 2.81 KB
/
IPResult.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
declare(strict_types=1);
namespace AndrewBreksa\ExtremeIPLookup;
use ArrayAccess;
use JsonSerializable;
/**
* Class IPResult
* @package AndrewBreksa\ExtremeIPLookup
* @author Andrew Breksa <andrew@andrewbreksa.com>
* @implements ArrayAccess<string, string>
*
* @property string $businessName
* @property string $businessWebsite
* @property string $city
* @property string $continent
* @property string $country
* @property string $countryCode
* @property string $ipName
* @property string $ipType
* @property string $isp
* @property string $lat
* @property string $lon
* @property string $org
* @property string $region
* @property string $timezone
* @property string $utcOffset
*/
class IPResult implements JsonSerializable, ArrayAccess
{
/**
* @var array<string, string>
*/
protected $data = [];
/**
* IPResult constructor.
* @param array<string, string> $data
*/
public function __construct(array $data)
{
$this->data = $data;
}
/**
* @param string $key
* @param null $default
* @return string|null
*/
public function get(string $key, $default = null)
{
if (!$this->has($key)) {
return $default;
}
return $this->offsetGet($key);
}
/**
* @param string $key
* @return bool
*/
public function has(string $key): bool
{
return $this->offsetExists($key);
}
/**
* @param string $offset
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return array_key_exists($offset, $this->data);
}
/**
* @param string $offset
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->data[$offset];
}
/**
* @return array<string, string>
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->data;
}
/**
* @param string $offset
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
/**
* @param string $key
* @return string
*/
public function __get(string $key)
{
return $this->offsetGet($key);
}
/**
* @param string $key
* @param string $value
*/
public function __set(string $key, string $value): void
{
$this->offsetSet($key, $value);
}
/**
* @param string $offset
* @param string $value
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->data[$offset] = $value;
}
/**
* @param string $key
* @return bool
*/
public function __isset(string $key)
{
return $this->offsetExists($key);
}
}