1 | <?php |
||
10 | class Validator extends AbstractCalculator |
||
11 | { |
||
12 | private $regexs = array( |
||
13 | 0 => '/^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z][0-9]{3}[a-z]$/i', |
||
14 | 1 => '/^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z][0-9]{2}[a-z]{2}$/i', |
||
15 | 2 => '/^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z][0-9][a-z]{3}$/i', |
||
16 | 3 => '/^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z]{5}$/i', |
||
17 | 4 => '/^[a-z]{6}[0-9]{2}[a-z][0-9][a-z]{6}$/i', |
||
18 | 5 => '/^[a-z]{6}[0-9]{2}[a-z]{8}$/i', |
||
19 | 6 => '/^[a-z]{6}[0-9][a-z]{9}$/i', |
||
20 | 7 => '/^[a-z]{16}$/i', |
||
21 | ); |
||
22 | private $omocodiaPositions = array(14, 13, 12, 10, 9, 7, 6); |
||
23 | |||
24 | private $codiceFiscale; |
||
25 | private $omocodiaAllowed = true; |
||
26 | private $century = null; |
||
27 | |||
28 | private $foundOmocodiaLevel = null; |
||
29 | private $codiceFiscaleWithoutOmocodia = null; |
||
30 | private $birthDate = null; |
||
31 | private $gender = null; |
||
32 | |||
33 | private $error = null; |
||
34 | private $isValid = false; |
||
35 | |||
36 | /** |
||
37 | * Create a Validator instance. |
||
38 | * |
||
39 | * @param string $codiceFiscale the codice fiscale to validate |
||
40 | * @param array $properties An array with additional properties. |
||
41 | */ |
||
42 | 18 | public function __construct($codiceFiscale, $properties = array()) |
|
70 | |||
71 | /** |
||
72 | * Validates length |
||
73 | * |
||
74 | * @throws \Exception |
||
75 | */ |
||
76 | 18 | private function validateLength() |
|
88 | |||
89 | /** |
||
90 | * Validates format |
||
91 | * |
||
92 | * @throws \Exception |
||
93 | */ |
||
94 | 18 | private function validateFormat() |
|
120 | |||
121 | /** |
||
122 | * Validates check digit |
||
123 | * |
||
124 | * @throws \Exception |
||
125 | */ |
||
126 | 18 | private function validateCheckDigit() |
|
133 | |||
134 | /** |
||
135 | * Validates omocodia and replace with matching chars |
||
136 | * |
||
137 | * @throws \Exception |
||
138 | */ |
||
139 | 17 | private function validateAndReplaceOmocodia() |
|
152 | |||
153 | /** |
||
154 | * Validates birthdate and gender |
||
155 | * |
||
156 | * @throws \Exception |
||
157 | */ |
||
158 | 17 | private function validateBirthDateAndGender() |
|
206 | |||
207 | /** |
||
208 | * Return the validation error |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | public function getError() |
||
216 | |||
217 | /** |
||
218 | * Return true if the provided codice fiscale is valid, false otherwise |
||
219 | * |
||
220 | * @return boolean |
||
221 | */ |
||
222 | 18 | public function isFormallyValid() |
|
226 | |||
227 | /** |
||
228 | * Return true if the provided codice fiscale is an omocodia, false otherwise |
||
229 | * |
||
230 | * @return boolean |
||
231 | */ |
||
232 | public function isOmocodia() |
||
236 | |||
237 | /** |
||
238 | * Return the provided codice fiscale, cleaned up by omocodia |
||
239 | * |
||
240 | * @return string |
||
241 | */ |
||
242 | 15 | protected function getCodiceFiscaleWithoutOmocodia() |
|
246 | |||
247 | /** |
||
248 | * Return the birth date |
||
249 | * |
||
250 | * @return \DateTime |
||
251 | */ |
||
252 | 15 | protected function getBirthDate() |
|
256 | |||
257 | /** |
||
258 | * Return the gender |
||
259 | * |
||
260 | * @return string |
||
261 | */ |
||
262 | 15 | protected function getGender() |
|
266 | } |
||
267 |