1 | <?php |
||
16 | abstract class AbstractDocument implements DigitCalculable, Formattable |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $number; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $digit; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $length; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $numberOfDigits; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $type; |
||
42 | |||
43 | /** |
||
44 | * AbstractDocument constructor. |
||
45 | * |
||
46 | * @param string $number Numeric section with checker digit. |
||
47 | * @param int $length Max length of document. |
||
48 | * @param int $numberOfDigits Max length of checker digits. |
||
49 | * @param string $type Document name/type. |
||
50 | */ |
||
51 | 1306 | public function __construct($number, $length, $numberOfDigits, $type) |
|
60 | |||
61 | 5 | public function __get($name) |
|
65 | |||
66 | public function __set($name, $value) |
||
70 | |||
71 | /** |
||
72 | * Create a Document object from given number. |
||
73 | * |
||
74 | * @param string $number Numeric section with checker digit. |
||
75 | * |
||
76 | * @return AbstractDocument|boolean Returns a new Document instance or FALSE on failure. |
||
77 | */ |
||
78 | abstract public static function createFromString($number); |
||
79 | |||
80 | /** |
||
81 | * Try to create a Document object from given number. |
||
82 | * |
||
83 | * @param string $number Numeric section with checker digit. |
||
84 | * @param int $length Max length of document. |
||
85 | * @param int $numberOfDigits Max length of checker digits. |
||
86 | * @param string $type Document name/type. |
||
87 | * |
||
88 | * @return AbstractDocument|boolean Returns a new Document instance or FALSE on failure. |
||
89 | */ |
||
90 | 167 | protected static function tryCreateFromString($class, $number, $length, $numberOfDigits, $type) |
|
98 | |||
99 | /** |
||
100 | * Handle number to string. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 883 | public function __toString() |
|
108 | |||
109 | /** |
||
110 | * Check if document number is valid. |
||
111 | * |
||
112 | * @param string $number Numeric section with checker digit. |
||
113 | * |
||
114 | * @throws Exception\InvalidDocument when number is empty |
||
115 | * @throws Exception\InvalidDocument when number is not valid |
||
116 | */ |
||
117 | 1306 | protected function assert($number) |
|
126 | |||
127 | /** |
||
128 | * Validates number is a valid. |
||
129 | * |
||
130 | * @param string $number Numeric section with checker digit. |
||
131 | * |
||
132 | * @return bool Returns true if it is a valid number, otherwise false. |
||
133 | */ |
||
134 | 1152 | protected function isValid($number) |
|
152 | |||
153 | /** |
||
154 | * Extracts the base number document. |
||
155 | * |
||
156 | * @param string $number Number of document. |
||
157 | * |
||
158 | * @return string Returns only base number without checker digit. |
||
159 | */ |
||
160 | 248 | protected function extractBaseNumber($number) |
|
164 | |||
165 | /** |
||
166 | * Extracts the checker digit from document number. |
||
167 | * |
||
168 | * @param string $number Number of document. |
||
169 | * |
||
170 | * @return string Returns only checker digit. |
||
171 | */ |
||
172 | 318 | protected function extractCheckerDigit($number) |
|
176 | } |
||
177 |