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