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 GeoIP2 Domain model.
11
 */
12
class Domain implements \JsonSerializable
13
{
14
    /**
15
     * @var string|null The second level domain associated with the
16
     *                  IP address. This will be something like "example.com" or
17
     *                  "example.co.uk", not "foo.example.com".
18
     */
19
    public readonly ?string $domain;
20
 
21
    /**
22
     * @var string the IP address that the data in the model is
23
     *             for
24
     */
25
    public readonly string $ipAddress;
26
 
27
    /**
28
     * @var string 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
     */
32
    public readonly string $network;
33
 
34
    /**
35
     * @ignore
36
     *
37
     * @param array<string, mixed> $raw
38
     */
39
    public function __construct(array $raw)
40
    {
41
        $this->domain = $raw['domain'] ?? null;
42
        $ipAddress = $raw['ip_address'];
43
        $this->ipAddress = $ipAddress;
44
        $this->network = Util::cidr($ipAddress, $raw['prefix_len']);
45
    }
46
 
47
    /**
48
     * @return array<string, mixed>|null
49
     */
50
    public function jsonSerialize(): ?array
51
    {
52
        $js = [];
53
        if ($this->domain !== null) {
54
            $js['domain'] = $this->domain;
55
        }
56
        $js['ip_address'] = $this->ipAddress;
57
        $js['network'] = $this->network;
58
 
59
        return $js;
60
    }
61
}