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 | public function __construct($codiceFiscale, $properties = array()) { |
||
69 | |||
70 | /** |
||
71 | * Validates length |
||
72 | * |
||
73 | * @throws \Exception |
||
74 | */ |
||
75 | private function validateLength() { |
||
86 | |||
87 | /** |
||
88 | * Validates format |
||
89 | * |
||
90 | * @throws \Exception |
||
91 | */ |
||
92 | private function validateFormat() { |
||
117 | |||
118 | /** |
||
119 | * Validates check digit |
||
120 | * |
||
121 | * @throws \Exception |
||
122 | */ |
||
123 | private function validateCheckDigit() { |
||
129 | |||
130 | /** |
||
131 | * Validates omocodia and replace with matching chars |
||
132 | * |
||
133 | * @throws \Exception |
||
134 | */ |
||
135 | private function validateAndReplaceOmocodia() { |
||
147 | |||
148 | /** |
||
149 | * Validates birthdate and gender |
||
150 | * |
||
151 | * @throws \Exception |
||
152 | */ |
||
153 | private function validateBirthDateAndGender() { |
||
200 | |||
201 | /** |
||
202 | * Return the validation error |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | public function getError() { |
||
209 | |||
210 | /** |
||
211 | * Return true if the provided codice fiscale is valid, false otherwise |
||
212 | * |
||
213 | * @return boolean |
||
214 | */ |
||
215 | public function isFormallyValid() { |
||
218 | |||
219 | /** |
||
220 | * Return true if the provided codice fiscale is an omocodia, false otherwise |
||
221 | * |
||
222 | * @return boolean |
||
223 | */ |
||
224 | public function isOmocodia() { |
||
227 | |||
228 | /** |
||
229 | * Return the provided codice fiscale, cleaned up by omocodia |
||
230 | * |
||
231 | * @return string |
||
232 | */ |
||
233 | protected function getCodiceFiscaleWithoutOmocodia() { |
||
236 | |||
237 | /** |
||
238 | * Return the birth date |
||
239 | * |
||
240 | * @return \DateTime |
||
241 | */ |
||
242 | protected function getBirthDate() { |
||
245 | |||
246 | /** |
||
247 | * Return the gender |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | protected function getGender() { |
||
254 | |||
255 | } |
||
256 |