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\Record\Continent;
8
use GeoIp2\Record\Country as CountryRecord;
9
use GeoIp2\Record\MaxMind;
10
use GeoIp2\Record\RepresentedCountry;
11
use GeoIp2\Record\Traits;
12
 
13
/**
14
 * Model class for the data returned by GeoIP2 Country web service and database.
15
 *
16
 * See https://dev.maxmind.com/geoip/docs/web-services?lang=en for more details.
17
 */
18
class Country implements \JsonSerializable
19
{
20
    /**
21
     * @var Continent continent data for the requested IP address
22
     */
23
    public readonly Continent $continent;
24
 
25
    /**
26
     * @var CountryRecord Country data for the requested IP address. This
27
     *                    object represents the country where MaxMind believes
28
     *                    the end user is located.
29
     */
30
    public readonly CountryRecord $country;
31
 
32
    /**
33
     * @var MaxMind data related to your MaxMind account
34
     */
35
    public readonly MaxMind $maxmind;
36
 
37
    /**
38
     * @var CountryRecord Registered country data for the requested IP address.
39
     *                    This record represents the country where the ISP has
40
     *                    registered a given IP block and may differ from the
41
     *                    user's country.
42
     */
43
    public readonly CountryRecord $registeredCountry;
44
 
45
    /**
46
     * @var RepresentedCountry Represented country data for the requested IP
47
     *                         address. The represented country is used for
48
     *                         things like military bases. It is only present
49
     *                         when the represented country differs from the
50
     *                         country.
51
     */
52
    public readonly RepresentedCountry $representedCountry;
53
 
54
    /**
55
     * @var Traits data for the traits of the requested IP address
56
     */
57
    public readonly Traits $traits;
58
 
59
    /**
60
     * @ignore
61
     *
62
     * @param array<string, mixed> $raw
63
     * @param list<string>         $locales
64
     */
65
    public function __construct(array $raw, array $locales = ['en'])
66
    {
67
        $this->continent = new Continent(
68
            $raw['continent'] ?? [],
69
            $locales
70
        );
71
        $this->country = new CountryRecord(
72
            $raw['country'] ?? [],
73
            $locales
74
        );
75
        $this->maxmind = new MaxMind($raw['maxmind'] ?? []);
76
        $this->registeredCountry = new CountryRecord(
77
            $raw['registered_country'] ?? [],
78
            $locales
79
        );
80
        $this->representedCountry = new RepresentedCountry(
81
            $raw['represented_country'] ?? [],
82
            $locales
83
        );
84
        $this->traits = new Traits($raw['traits'] ?? []);
85
    }
86
 
87
    /**
88
     * @return array<string, mixed>|null
89
     */
90
    public function jsonSerialize(): ?array
91
    {
92
        $js = [];
93
        $continent = $this->continent->jsonSerialize();
94
        if (!empty($continent)) {
95
            $js['continent'] = $continent;
96
        }
97
        $country = $this->country->jsonSerialize();
98
        if (!empty($country)) {
99
            $js['country'] = $country;
100
        }
101
        $maxmind = $this->maxmind->jsonSerialize();
102
        if (!empty($maxmind)) {
103
            $js['maxmind'] = $maxmind;
104
        }
105
        $registeredCountry = $this->registeredCountry->jsonSerialize();
106
        if (!empty($registeredCountry)) {
107
            $js['registered_country'] = $registeredCountry;
108
        }
109
        $representedCountry = $this->representedCountry->jsonSerialize();
110
        if (!empty($representedCountry)) {
111
            $js['represented_country'] = $representedCountry;
112
        }
113
        $traits = $this->traits->jsonSerialize();
114
        if (!empty($traits)) {
115
            $js['traits'] = $traits;
116
        }
117
 
118
        return $js;
119
    }
120
}