Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace GeoIp2\Record;
6
 
7
abstract class AbstractPlaceRecord extends AbstractRecord
8
{
9
    /**
10
     * @var array<string>
11
     */
12
    private $locales;
13
 
14
    /**
15
     * @ignore
16
     */
17
    public function __construct(?array $record, array $locales = ['en'])
18
    {
19
        $this->locales = $locales;
20
        parent::__construct($record);
21
    }
22
 
23
    /**
24
     * @ignore
25
     *
26
     * @return mixed
27
     */
28
    public function __get(string $attr)
29
    {
30
        if ($attr === 'name') {
31
            return $this->name();
32
        }
33
 
34
        return parent::__get($attr);
35
    }
36
 
37
    /**
38
     * @ignore
39
     */
40
    public function __isset(string $attr): bool
41
    {
42
        if ($attr === 'name') {
43
            return $this->firstSetNameLocale() !== null;
44
        }
45
 
46
        return parent::__isset($attr);
47
    }
48
 
49
    private function name(): ?string
50
    {
51
        $locale = $this->firstSetNameLocale();
52
 
53
        // @phpstan-ignore-next-line
54
        return $locale === null ? null : $this->names[$locale];
55
    }
56
 
57
    private function firstSetNameLocale(): ?string
58
    {
59
        foreach ($this->locales as $locale) {
60
            if (isset($this->names[$locale])) {
61
                return $locale;
62
            }
63
        }
64
 
65
        return null;
66
    }
67
}