-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathDetailsPlus.php
More file actions
52 lines (48 loc) · 1.3 KB
/
DetailsPlus.php
File metadata and controls
52 lines (48 loc) · 1.3 KB
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
<?php
namespace ipinfo\ipinfo;
/**
* Holds formatted data received from Plus API for a single IP address.
*/
class DetailsPlus
{
public $ip;
public $hostname;
public $geo;
public $asn;
public $mobile;
public $anonymous;
public $is_anonymous;
public $is_anycast;
public $is_hosting;
public $is_mobile;
public $is_satellite;
public $abuse;
public $company;
public $privacy;
public $domains;
public $bogon;
public $all;
public function __construct($raw_details)
{
foreach ($raw_details as $property => $value) {
// Handle nested 'as' object - rename to 'asn' to avoid PHP keyword
if ($property === 'as') {
$this->asn = (object) $value;
} elseif (in_array($property, ['geo', 'mobile', 'anonymous', 'abuse', 'company', 'privacy', 'domains'])) {
$this->$property = (object) $value;
} else {
$this->$property = $value;
}
}
$this->all = $raw_details;
}
/**
* Returns json string representation.
*
* @internal this class should implement Stringable explicitly when leaving support for PHP verision < 8.0
*/
public function __toString(): string
{
return json_encode($this);
}
}