|
8 | 8 |
|
9 | 9 | /** |
10 | 10 | * This class provides the GeoIP2 Anonymous IP model. |
11 | | - * |
12 | | - * @property-read bool $isAnonymous This is true if the IP address belongs to |
13 | | - * any sort of anonymous network. |
14 | | - * @property-read bool $isAnonymousVpn This is true if the IP address is |
15 | | - * registered to an anonymous VPN provider. If a VPN provider does not |
16 | | - * register subnets under names associated with them, we will likely only |
17 | | - * flag their IP ranges using the isHostingProvider property. |
18 | | - * @property-read bool $isHostingProvider This is true if the IP address belongs |
19 | | - * to a hosting or VPN provider (see description of isAnonymousVpn property). |
20 | | - * @property-read bool $isPublicProxy This is true if the IP address belongs to |
21 | | - * a public proxy. |
22 | | - * @property-read bool $isResidentialProxy This is true if the IP address is |
23 | | - * on a suspected anonymizing network and belongs to a residential ISP. |
24 | | - * @property-read bool $isTorExitNode This is true if the IP address is a Tor |
25 | | - * exit node. |
26 | | - * @property-read string $ipAddress The IP address that the data in the model is |
27 | | - * for. |
28 | | - * @property-read string $network The network in CIDR notation associated with |
29 | | - * the record. In particular, this is the largest network where all of the |
30 | | - * fields besides $ipAddress have the same value. |
31 | 11 | */ |
32 | | -class AnonymousIp extends AbstractModel |
| 12 | +class AnonymousIp implements \JsonSerializable |
33 | 13 | { |
34 | | - protected bool $isAnonymous; |
35 | | - protected bool $isAnonymousVpn; |
36 | | - protected bool $isHostingProvider; |
37 | | - protected bool $isPublicProxy; |
38 | | - protected bool $isResidentialProxy; |
39 | | - protected bool $isTorExitNode; |
40 | | - protected string $ipAddress; |
41 | | - protected string $network; |
| 14 | + /** |
| 15 | + * @var bool this is true if the IP address belongs to |
| 16 | + * any sort of anonymous network |
| 17 | + */ |
| 18 | + public readonly bool $isAnonymous; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var bool This is true if the IP address is |
| 22 | + * registered to an anonymous VPN provider. If a VPN provider does not |
| 23 | + * register subnets under names associated with them, we will likely only |
| 24 | + * flag their IP ranges using the isHostingProvider property. |
| 25 | + */ |
| 26 | + public readonly bool $isAnonymousVpn; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var bool this is true if the IP address belongs |
| 30 | + * to a hosting or VPN provider (see description of isAnonymousVpn property) |
| 31 | + */ |
| 32 | + public readonly bool $isHostingProvider; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var bool this is true if the IP address belongs to |
| 36 | + * a public proxy |
| 37 | + */ |
| 38 | + public readonly bool $isPublicProxy; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var bool this is true if the IP address is |
| 42 | + * on a suspected anonymizing network and belongs to a residential ISP |
| 43 | + */ |
| 44 | + public readonly bool $isResidentialProxy; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var bool this is true if the IP address is a Tor |
| 48 | + * exit node |
| 49 | + */ |
| 50 | + public readonly bool $isTorExitNode; |
| 51 | + |
| 52 | + /** |
| 53 | + * @var string the IP address that the data in the model is |
| 54 | + * for |
| 55 | + */ |
| 56 | + public readonly string $ipAddress; |
| 57 | + |
| 58 | + /** |
| 59 | + * @var string The network in CIDR notation associated with |
| 60 | + * the record. In particular, this is the largest network where all of the |
| 61 | + * fields besides $ipAddress have the same value. |
| 62 | + */ |
| 63 | + public readonly string $network; |
42 | 64 |
|
43 | 65 | /** |
44 | 66 | * @ignore |
45 | 67 | */ |
46 | 68 | public function __construct(array $raw) |
47 | 69 | { |
48 | | - parent::__construct($raw); |
49 | | - |
50 | | - $this->isAnonymous = $this->get('is_anonymous'); |
51 | | - $this->isAnonymousVpn = $this->get('is_anonymous_vpn'); |
52 | | - $this->isHostingProvider = $this->get('is_hosting_provider'); |
53 | | - $this->isPublicProxy = $this->get('is_public_proxy'); |
54 | | - $this->isResidentialProxy = $this->get('is_residential_proxy'); |
55 | | - $this->isTorExitNode = $this->get('is_tor_exit_node'); |
56 | | - $ipAddress = $this->get('ip_address'); |
| 70 | + $this->isAnonymous = $raw['is_anonymous'] ?? false; |
| 71 | + $this->isAnonymousVpn = $raw['is_anonymous_vpn'] ?? false; |
| 72 | + $this->isHostingProvider = $raw['is_hosting_provider'] ?? false; |
| 73 | + $this->isPublicProxy = $raw['is_public_proxy'] ?? false; |
| 74 | + $this->isResidentialProxy = $raw['is_residential_proxy'] ?? false; |
| 75 | + $this->isTorExitNode = $raw['is_tor_exit_node'] ?? false; |
| 76 | + $ipAddress = $raw['ip_address']; |
57 | 77 | $this->ipAddress = $ipAddress; |
58 | | - $this->network = Util::cidr($ipAddress, $this->get('prefix_len')); |
| 78 | + $this->network = Util::cidr($ipAddress, $raw['prefix_len']); |
| 79 | + } |
| 80 | + |
| 81 | + public function jsonSerialize(): ?array |
| 82 | + { |
| 83 | + $js = []; |
| 84 | + if ($this->isAnonymous !== null) { |
| 85 | + $js['is_anonymous'] = $this->isAnonymous; |
| 86 | + } |
| 87 | + if ($this->isAnonymousVpn !== null) { |
| 88 | + $js['is_anonymous_vpn'] = $this->isAnonymousVpn; |
| 89 | + } |
| 90 | + if ($this->isHostingProvider !== null) { |
| 91 | + $js['is_hosting_provider'] = $this->isHostingProvider; |
| 92 | + } |
| 93 | + if ($this->isPublicProxy !== null) { |
| 94 | + $js['is_public_proxy'] = $this->isPublicProxy; |
| 95 | + } |
| 96 | + if ($this->isResidentialProxy !== null) { |
| 97 | + $js['is_residential_proxy'] = $this->isResidentialProxy; |
| 98 | + } |
| 99 | + if ($this->isTorExitNode !== null) { |
| 100 | + $js['is_tor_exit_node'] = $this->isTorExitNode; |
| 101 | + } |
| 102 | + $js['ip_address'] = $this->ipAddress; |
| 103 | + $js['network'] = $this->network; |
| 104 | + |
| 105 | + return $js; |
59 | 106 | } |
60 | 107 | } |
0 commit comments