|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace GeoIp2\Record; |
| 6 | + |
| 7 | +/** |
| 8 | + * Contains data for the anonymizer record associated with an IP address. |
| 9 | + * |
| 10 | + * This record is returned by the GeoIP2 Insights web service. |
| 11 | + */ |
| 12 | +class Anonymizer implements \JsonSerializable |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var int|null A confidence score from 1-99 indicating our confidence that the |
| 16 | + * IP address is a VPN. Currently, this is either 30 or 99. This attribute |
| 17 | + * is only available from the GeoIP2 Insights web service. |
| 18 | + */ |
| 19 | + public readonly ?int $confidence; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var bool This is true if the IP address belongs to |
| 23 | + * any sort of anonymous network. This attribute is only available from the |
| 24 | + * GeoIP2 Insights web service. |
| 25 | + */ |
| 26 | + public readonly bool $isAnonymous; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var bool This is true if the IP address is |
| 30 | + * registered to an anonymous VPN provider. If a VPN provider does not register |
| 31 | + * subnets under names associated with them, we will likely only flag their IP |
| 32 | + * ranges using the isHostingProvider property. This attribute is only available |
| 33 | + * from the GeoIP2 Insights web service. |
| 34 | + */ |
| 35 | + public readonly bool $isAnonymousVpn; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var bool This is true if the IP address belongs |
| 39 | + * to a hosting or VPN provider (see description of isAnonymousVpn property). |
| 40 | + * This attribute is only available from the GeoIP2 Insights web service. |
| 41 | + */ |
| 42 | + public readonly bool $isHostingProvider; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var bool This is true if the IP address belongs to |
| 46 | + * a public proxy. This attribute is only available from the GeoIP2 Insights |
| 47 | + * web service. |
| 48 | + */ |
| 49 | + public readonly bool $isPublicProxy; |
| 50 | + |
| 51 | + /** |
| 52 | + * @var bool This is true if the IP address is |
| 53 | + * on a suspected anonymizing network and belongs to a residential ISP. This |
| 54 | + * attribute is only available from the GeoIP2 Insights web service. |
| 55 | + */ |
| 56 | + public readonly bool $isResidentialProxy; |
| 57 | + |
| 58 | + /** |
| 59 | + * @var bool This is true if the IP address is a Tor |
| 60 | + * exit node. This attribute is only available from the GeoIP2 Insights |
| 61 | + * web service. |
| 62 | + */ |
| 63 | + public readonly bool $isTorExitNode; |
| 64 | + |
| 65 | + /** |
| 66 | + * @var string|null The date the anonymizer network was last seen in |
| 67 | + * YYYY-MM-DD format. This attribute is only available from the GeoIP2 |
| 68 | + * Insights web service. |
| 69 | + */ |
| 70 | + public readonly ?string $networkLastSeen; |
| 71 | + |
| 72 | + /** |
| 73 | + * @var string|null The name of the VPN provider, for example, NordVPN or |
| 74 | + * SurfShark. This attribute is only available from the GeoIP2 Insights |
| 75 | + * web service. |
| 76 | + */ |
| 77 | + public readonly ?string $providerName; |
| 78 | + |
| 79 | + /** |
| 80 | + * @ignore |
| 81 | + * |
| 82 | + * @param array<string, mixed> $record |
| 83 | + */ |
| 84 | + public function __construct(array $record) |
| 85 | + { |
| 86 | + $this->confidence = $record['confidence'] ?? null; |
| 87 | + $this->isAnonymous = $record['is_anonymous'] ?? false; |
| 88 | + $this->isAnonymousVpn = $record['is_anonymous_vpn'] ?? false; |
| 89 | + $this->isHostingProvider = $record['is_hosting_provider'] ?? false; |
| 90 | + $this->isPublicProxy = $record['is_public_proxy'] ?? false; |
| 91 | + $this->isResidentialProxy = $record['is_residential_proxy'] ?? false; |
| 92 | + $this->isTorExitNode = $record['is_tor_exit_node'] ?? false; |
| 93 | + $this->networkLastSeen = $record['network_last_seen'] ?? null; |
| 94 | + $this->providerName = $record['provider_name'] ?? null; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * @return array<string, mixed> |
| 99 | + */ |
| 100 | + public function jsonSerialize(): array |
| 101 | + { |
| 102 | + $js = []; |
| 103 | + |
| 104 | + if ($this->confidence !== null) { |
| 105 | + $js['confidence'] = $this->confidence; |
| 106 | + } |
| 107 | + if ($this->isAnonymous !== false) { |
| 108 | + $js['is_anonymous'] = $this->isAnonymous; |
| 109 | + } |
| 110 | + if ($this->isAnonymousVpn !== false) { |
| 111 | + $js['is_anonymous_vpn'] = $this->isAnonymousVpn; |
| 112 | + } |
| 113 | + if ($this->isHostingProvider !== false) { |
| 114 | + $js['is_hosting_provider'] = $this->isHostingProvider; |
| 115 | + } |
| 116 | + if ($this->isPublicProxy !== false) { |
| 117 | + $js['is_public_proxy'] = $this->isPublicProxy; |
| 118 | + } |
| 119 | + if ($this->isResidentialProxy !== false) { |
| 120 | + $js['is_residential_proxy'] = $this->isResidentialProxy; |
| 121 | + } |
| 122 | + if ($this->isTorExitNode !== false) { |
| 123 | + $js['is_tor_exit_node'] = $this->isTorExitNode; |
| 124 | + } |
| 125 | + if ($this->networkLastSeen !== null) { |
| 126 | + $js['network_last_seen'] = $this->networkLastSeen; |
| 127 | + } |
| 128 | + if ($this->providerName !== null) { |
| 129 | + $js['provider_name'] = $this->providerName; |
| 130 | + } |
| 131 | + |
| 132 | + return $js; |
| 133 | + } |
| 134 | +} |
0 commit comments