| 1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace GeoIp2\Record;
|
|
|
6 |
|
|
|
7 |
/**
|
|
|
8 |
* Contains data for the country record associated with an IP address.
|
|
|
9 |
*
|
|
|
10 |
* This record is returned by all location services and databases.
|
|
|
11 |
*/
|
|
|
12 |
class Country extends AbstractPlaceRecord
|
|
|
13 |
{
|
|
|
14 |
/**
|
|
|
15 |
* @var bool This is true if the country is a
|
|
|
16 |
* member state of the European Union. This attribute is returned by all
|
|
|
17 |
* location services and databases.
|
|
|
18 |
*/
|
|
|
19 |
public readonly bool $isInEuropeanUnion;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* @var string|null The two-character ISO 3166-1 alpha code
|
|
|
23 |
* for the country. See https://en.wikipedia.org/wiki/ISO_3166-1. This
|
|
|
24 |
* attribute is returned by all location services and databases.
|
|
|
25 |
*/
|
|
|
26 |
public readonly ?string $isoCode;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* @ignore
|
|
|
30 |
*
|
|
|
31 |
* @param array<string, mixed> $record
|
|
|
32 |
* @param list<string> $locales
|
|
|
33 |
*/
|
|
|
34 |
public function __construct(array $record, array $locales = ['en'])
|
|
|
35 |
{
|
|
|
36 |
parent::__construct($record, $locales);
|
|
|
37 |
|
|
|
38 |
$this->isInEuropeanUnion = $record['is_in_european_union'] ?? false;
|
|
|
39 |
$this->isoCode = $record['iso_code'] ?? null;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* @return array<string, mixed>
|
|
|
44 |
*/
|
|
|
45 |
public function jsonSerialize(): array
|
|
|
46 |
{
|
|
|
47 |
$js = parent::jsonSerialize();
|
|
|
48 |
if ($this->isInEuropeanUnion !== false) {
|
|
|
49 |
$js['is_in_european_union'] = $this->isInEuropeanUnion;
|
|
|
50 |
}
|
|
|
51 |
if ($this->isoCode !== null) {
|
|
|
52 |
$js['iso_code'] = $this->isoCode;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
return $js;
|
|
|
56 |
}
|
|
|
57 |
}
|