|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2017 Alexandru Guzinschi <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This software may be modified and distributed under the terms |
|
6
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Vimishor\Cnp; |
|
9
|
|
|
|
|
10
|
|
|
use Gentle\Embeddable\Embeddable; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @author Alexandru Guzinschi <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
final class County extends Embeddable |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var array */ |
|
18
|
|
|
private static $counties = [ |
|
19
|
|
|
'01' => 'Alba', |
|
20
|
|
|
'02' => 'Arad', |
|
21
|
|
|
'03' => 'Arges', |
|
22
|
|
|
'04' => 'Bacau', |
|
23
|
|
|
'05' => 'Bihor', |
|
24
|
|
|
'06' => 'Bistrita-Nasaud', |
|
25
|
|
|
'07' => 'Botosani', |
|
26
|
|
|
'08' => 'Brasov', |
|
27
|
|
|
'09' => 'Braila', |
|
28
|
|
|
'10' => 'Buzau', |
|
29
|
|
|
'11' => 'Caras-Severin', |
|
30
|
|
|
'12' => 'Cluj', |
|
31
|
|
|
'13' => 'Constanta', |
|
32
|
|
|
'14' => 'Covasna', |
|
33
|
|
|
'15' => 'Dambovita', |
|
34
|
|
|
'16' => 'Dolj', |
|
35
|
|
|
'17' => 'Galati', |
|
36
|
|
|
'18' => 'Gorj', |
|
37
|
|
|
'19' => 'Harghita', |
|
38
|
|
|
'20' => 'Hunedoara', |
|
39
|
|
|
'21' => 'Ialomita', |
|
40
|
|
|
'22' => 'Iasi', |
|
41
|
|
|
'23' => 'Ilfov', |
|
42
|
|
|
'24' => 'Maramures', |
|
43
|
|
|
'25' => 'Mehedinti', |
|
44
|
|
|
'26' => 'Mures', |
|
45
|
|
|
'27' => 'Neamt', |
|
46
|
|
|
'28' => 'Olt', |
|
47
|
|
|
'29' => 'Prahova', |
|
48
|
|
|
'30' => 'Satu Mare', |
|
49
|
|
|
'31' => 'Salaj', |
|
50
|
|
|
'32' => 'Sibiu', |
|
51
|
|
|
'33' => 'Suceava', |
|
52
|
|
|
'34' => 'Teleorman', |
|
53
|
|
|
'35' => 'Timis', |
|
54
|
|
|
'36' => 'Tulcea', |
|
55
|
|
|
'37' => 'Vaslui', |
|
56
|
|
|
'38' => 'Valcea', |
|
57
|
|
|
'39' => 'Vrancea', |
|
58
|
|
|
'40' => 'Bucuresti', |
|
59
|
|
|
'41' => 'Bucuresti/Sectorul 1', |
|
60
|
|
|
'42' => 'Bucuresti/Sectorul 2', |
|
61
|
|
|
'43' => 'Bucuresti/Sectorul 3', // was merged with district 2 in 1979 => district 2 |
|
62
|
|
|
'44' => 'Bucuresti/Sectorul 4', // district 3 since 1979 |
|
63
|
|
|
'45' => 'Bucuresti/Sectorul 5', // district 4 since 1979 |
|
64
|
|
|
'46' => 'Bucuresti/Sectorul 6', // district 5 since 1979 |
|
65
|
|
|
'47' => 'Bucuresti/Sectorul 7', // district 6 since 1979 |
|
66
|
|
|
'48' => 'Bucuresti/Sectorul 8', // was merged with district 1 in 1979 => district 1 |
|
67
|
|
|
'51' => 'Calarasi', |
|
68
|
|
|
'52' => 'Giurgiu' |
|
69
|
|
|
]; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string|int $county |
|
73
|
|
|
* |
|
74
|
|
|
* @throws \InvalidArgumentException |
|
75
|
|
|
*/ |
|
76
|
76 |
|
public function __construct($county) |
|
77
|
|
|
{ |
|
78
|
76 |
|
if (is_int($county)) { |
|
79
|
26 |
|
$county = (string)$county; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
76 |
|
if (!is_string($county) && !ctype_digit($county)) { |
|
83
|
6 |
|
throw new \InvalidArgumentException(sprintf('Expected string or integer and got %s', gettype($county))); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
70 |
|
$county = str_pad((string)$county, 2, 0, STR_PAD_LEFT); |
|
87
|
|
|
|
|
88
|
70 |
|
if (!array_key_exists($county, self::$counties)) { |
|
89
|
14 |
|
throw new \InvalidArgumentException(sprintf('%s is not a known county.', $county)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
56 |
|
$this->value = $county; |
|
93
|
56 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @access public |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
12 |
|
public function getName() |
|
100
|
|
|
{ |
|
101
|
12 |
|
return self::$counties[$this->value]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritDoc} |
|
106
|
|
|
*/ |
|
107
|
12 |
|
public function equals(Embeddable $object) |
|
108
|
|
|
{ |
|
109
|
12 |
|
return get_class($object) === 'Vimishor\Cnp\County' && $this->value === (string)$object; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|