Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace GeoIp2\Model;
6
 
7
use GeoIp2\Util;
8
 
9
/**
10
 * This class provides the GeoLite2 ASN model.
11
 */
12
class Asn implements \JsonSerializable
13
{
14
    /**
15
     * @var int|null the autonomous system number
16
     *               associated with the IP address
17
     */
18
    public readonly ?int $autonomousSystemNumber;
19
 
20
    /**
21
     * @var string|null the organization
22
     *                  associated with the registered autonomous system number for the IP
23
     *                  address
24
     */
25
    public readonly ?string $autonomousSystemOrganization;
26
 
27
    /**
28
     * @var string the IP address that the data in the model is
29
     *             for
30
     */
31
    public readonly string $ipAddress;
32
 
33
    /**
34
     * @var string The network in CIDR notation associated with
35
     *             the record. In particular, this is the largest network where all of the
36
     *             fields besides $ipAddress have the same value.
37
     */
38
    public readonly string $network;
39
 
40
    /**
41
     * @ignore
42
     *
43
     * @param array<string, mixed> $raw
44
     */
45
    public function __construct(array $raw)
46
    {
47
        $this->autonomousSystemNumber = $raw['autonomous_system_number'] ?? null;
48
        $this->autonomousSystemOrganization =
49
            $raw['autonomous_system_organization'] ?? null;
50
        $ipAddress = $raw['ip_address'];
51
        $this->ipAddress = $ipAddress;
52
        $this->network = Util::cidr($ipAddress, $raw['prefix_len']);
53
    }
54
 
55
    /**
56
     * @return array<string, mixed>|null
57
     */
58
    public function jsonSerialize(): ?array
59
    {
60
        $js = [];
61
 
62
        if ($this->autonomousSystemNumber !== null) {
63
            $js['autonomous_system_number'] = $this->autonomousSystemNumber;
64
        }
65
        if ($this->autonomousSystemOrganization !== null) {
66
            $js['autonomous_system_organization'] = $this->autonomousSystemOrganization;
67
        }
68
        $js['ip_address'] = $this->ipAddress;
69
        $js['network'] = $this->network;
70
 
71
        return $js;
72
    }
73
}