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\Record;
6
 
7
/**
8
 * Contains data for the continent record associated with an IP address.
9
 *
10
 * This record is returned by all location services and databases.
11
 */
12
class Continent extends AbstractNamedRecord
13
{
14
    /**
15
     * @var string|null A two character continent code like "NA" (North
16
     *                  America) or "OC" (Oceania). This attribute is returned by all location
17
     *                  services and databases.
18
     */
19
    public readonly ?string $code;
20
 
21
    /**
22
     * @var int|null The GeoName ID for the continent. This
23
     *               attribute is returned by all location services and databases.
24
     */
25
    public readonly ?int $geonameId;
26
 
27
    /**
28
     * @ignore
29
     *
30
     * @param array<string, mixed> $record
31
     * @param list<string>         $locales
32
     */
33
    public function __construct(array $record, array $locales = ['en'])
34
    {
35
        parent::__construct($record, $locales);
36
 
37
        $this->code = $record['code'] ?? null;
38
        $this->geonameId = $record['geoname_id'] ?? null;
39
    }
40
 
41
    /**
42
     * @return array<string, mixed>
43
     */
44
    public function jsonSerialize(): array
45
    {
46
        $js = parent::jsonSerialize();
47
        if ($this->code !== null) {
48
            $js['code'] = $this->code;
49
        }
50
        if ($this->geonameId !== null) {
51
            $js['geoname_id'] = $this->geonameId;
52
        }
53
 
54
        return $js;
55
    }
56
}