1 | <?php |
||
8 | class PersonalId extends AbstractId |
||
9 | { |
||
10 | /** |
||
11 | * Regular expression describing id structure |
||
12 | */ |
||
13 | const PATTERN = '/^((?:\d\d)?)(\d{6})([-+]?)(\d{3})(\d)$/'; |
||
14 | |||
15 | /** |
||
16 | * @var string[] Map of county number high limit to county identifier |
||
17 | */ |
||
18 | private static $birthCountyMap = [ |
||
19 | 13 => Id::COUNTY_STOCKHOLM, |
||
20 | 15 => Id::COUNTY_UPPSALA, |
||
21 | 18 => Id::COUNTY_SODERMANLAND, |
||
22 | 23 => Id::COUNTY_OSTERGOTLAND, |
||
23 | 26 => Id::COUNTY_JONKOPING, |
||
24 | 28 => Id::COUNTY_KRONOBERG, |
||
25 | 31 => Id::COUNTY_KALMAR, |
||
26 | 32 => Id::COUNTY_GOTLAND, |
||
27 | 34 => Id::COUNTY_BLEKINGE, |
||
28 | 38 => Id::COUNTY_KRISTIANSTAD, |
||
29 | 45 => Id::COUNTY_MALMOHUS, |
||
30 | 47 => Id::COUNTY_HALLAND, |
||
31 | 54 => Id::COUNTY_GOTEBORG_BOUHUS, |
||
32 | 58 => Id::COUNTY_ALVSBORG, |
||
33 | 61 => Id::COUNTY_SKARABORG, |
||
34 | 64 => Id::COUNTY_VARMLAND, |
||
35 | 65 => Id::COUNTY_UNDEFINED, |
||
36 | 68 => Id::COUNTY_OREBRO, |
||
37 | 70 => Id::COUNTY_VASTMANLAND, |
||
38 | 73 => Id::COUNTY_KOPPARBERG, |
||
39 | 74 => Id::COUNTY_UNDEFINED, |
||
40 | 77 => Id::COUNTY_GAVLEBORG, |
||
41 | 81 => Id::COUNTY_VASTERNORRLAND, |
||
42 | 84 => Id::COUNTY_JAMTLAND, |
||
43 | 88 => Id::COUNTY_VASTERBOTTEN, |
||
44 | 92 => Id::COUNTY_NORRBOTTEN |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * @var \DateTime Date of birth |
||
49 | */ |
||
50 | private $date; |
||
51 | |||
52 | /** |
||
53 | * Swedish personal identity numbers |
||
54 | * |
||
55 | * Format is YYYYMMDD(+-)NNNC or YYMMDD(+-)NNNC where parenthesis represents |
||
56 | * an optional one char delimiter, N represents the individual number and C |
||
57 | * the check digit. If year is set using two digits century is calculated |
||
58 | * based on delimiter (+ signals more than a hundred years old). If year is |
||
59 | * set using four digits delimiter is calculated based on century. |
||
60 | * |
||
61 | * @param string $number |
||
62 | * @throws Exception\InvalidDateStructureException If date is not logically valid |
||
63 | */ |
||
64 | 97 | public function __construct($number) |
|
99 | |||
100 | /** |
||
101 | * Get date of birth |
||
102 | * |
||
103 | * @return \DateTime |
||
104 | */ |
||
105 | 21 | public function getBirthDate() |
|
109 | |||
110 | /** |
||
111 | * Get sex as denoted by id |
||
112 | * |
||
113 | * @return string One of the sex identifier constants |
||
114 | */ |
||
115 | 4 | public function getSex() |
|
119 | |||
120 | /** |
||
121 | * Get string describing birth county |
||
122 | * |
||
123 | * @return string One of the birth county identifier constants |
||
124 | */ |
||
125 | 3 | public function getBirthCounty() |
|
138 | } |
||
139 |