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 Connection-Type model.
11
 */
12
class ConnectionType implements \JsonSerializable
13
{
14
    /**
15
     * @var string|null The connection type may take the
16
     *                  following values: "Dialup", "Cable/DSL", "Corporate", "Cellular", and
17
     *                  "Satellite". Additional values may be added in the future.
18
     */
19
    public readonly ?string $connectionType;
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->connectionType = $raw['connection_type'] ?? 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->connectionType !== null) {
54
            $js['connection_type'] = $this->connectionType;
55
        }
56
        $js['ip_address'] = $this->ipAddress;
57
        $js['network'] = $this->network;
58
 
59
        return $js;
60
    }
61
}