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