-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathDetailsCore.php
More file actions
45 lines (41 loc) · 1.08 KB
/
DetailsCore.php
File metadata and controls
45 lines (41 loc) · 1.08 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
<?php
namespace ipinfo\ipinfo;
/**
* Holds formatted data received from Core API for a single IP address.
*/
class DetailsCore
{
public $ip;
public $geo;
public $asn;
public $is_anonymous;
public $is_anycast;
public $is_hosting;
public $is_mobile;
public $is_satellite;
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 ($property === 'geo') {
$this->geo = (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);
}
}