1 | <?php |
||
11 | abstract class Reader |
||
12 | { |
||
13 | const CONTAINS_HEADERS = 1; |
||
14 | const CONTAINS_DEFINITIONS = 2; |
||
15 | const CONTAINS_DATA = 4; |
||
16 | |||
17 | /** |
||
18 | * @var string Raw contents |
||
19 | */ |
||
20 | private $contents = null; |
||
21 | |||
22 | /** |
||
23 | * @var Collection Parsed header |
||
24 | */ |
||
25 | private $headers = null; |
||
26 | |||
27 | /** |
||
28 | * @var Collection Parsed definition |
||
29 | */ |
||
30 | private $definitions = null; |
||
31 | |||
32 | /** |
||
33 | * @var Collection Parsed data |
||
34 | */ |
||
35 | private $data = null; |
||
36 | |||
37 | /** |
||
38 | * @return Reader |
||
39 | */ |
||
40 | public static function create() |
||
44 | |||
45 | /** |
||
46 | * @param string $filePath Path to the BLM file |
||
47 | * |
||
48 | * @return $this |
||
49 | * |
||
50 | * @throws FileNotFoundException |
||
51 | * @throws InvalidBlmFileException |
||
52 | */ |
||
53 | final public function loadFromFile($filePath) |
||
67 | |||
68 | /** |
||
69 | * @param string $contents Contents of a BLM file |
||
70 | * |
||
71 | * @return Reader |
||
72 | * |
||
73 | * @throws InvalidBlmFileException |
||
74 | */ |
||
75 | final public function loadFromString($contents) |
||
83 | |||
84 | /** |
||
85 | * Return the output in the drivers format. |
||
86 | * |
||
87 | * @return mixed |
||
88 | */ |
||
89 | abstract public function getOutput(); |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | final public function getRawContents() |
||
98 | |||
99 | /** |
||
100 | * @return Collection |
||
101 | */ |
||
102 | final protected function getHeaders() |
||
106 | |||
107 | /** |
||
108 | * @return Collection |
||
109 | */ |
||
110 | final protected function getDefinitions() |
||
114 | |||
115 | /** |
||
116 | * @return Collection |
||
117 | */ |
||
118 | final protected function getData() |
||
122 | |||
123 | /** |
||
124 | * Validates a string. |
||
125 | * |
||
126 | * @param string $contents |
||
127 | * |
||
128 | * @return bool Returns true if content is valid |
||
129 | */ |
||
130 | final protected function containsValidBLM($contents) |
||
140 | |||
141 | /** |
||
142 | * Verifies if contents contain a headers sections. |
||
143 | * |
||
144 | * @param string $contents |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | final protected function containsHeader($contents) |
||
152 | |||
153 | /** |
||
154 | * Verifies if contents contain a headers sections. |
||
155 | * |
||
156 | * @param string $contents |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | final protected function containsDefinition($contents) |
||
164 | |||
165 | /** |
||
166 | * Verifies if contents contain a headers sections. |
||
167 | * |
||
168 | * @param string $contents |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | final protected function containsData($contents) |
||
176 | |||
177 | /** |
||
178 | * @param string $contents |
||
179 | * |
||
180 | * @return Reader |
||
181 | */ |
||
182 | final protected function parse($contents) |
||
194 | |||
195 | /** |
||
196 | * Parses the #HEADER# section of the BLM file and stores it in $this->headers. |
||
197 | * |
||
198 | * @param string $contents |
||
199 | */ |
||
200 | private function parseHeader($contents) |
||
219 | |||
220 | /** |
||
221 | * Parses the #DEFINITION# section of the BLM file and stores it in $this->definitions. |
||
222 | * |
||
223 | * @param string $contents |
||
224 | */ |
||
225 | private function parseDefinition($contents) |
||
243 | |||
244 | /** |
||
245 | * Parses the #DATA# section of the BLM file and stores it in $this->data. |
||
246 | * |
||
247 | * @param $contents |
||
248 | */ |
||
249 | private function parseData($contents) |
||
271 | |||
272 | /** |
||
273 | * @param $string |
||
274 | * |
||
275 | * @return VerbalExpressions |
||
276 | */ |
||
277 | private function getRegexFor($string) |
||
285 | |||
286 | /** |
||
287 | * @param $line |
||
288 | * |
||
289 | * @return bool |
||
290 | */ |
||
291 | private function isValidLineWithoutHash($line) |
||
295 | /** |
||
296 | * @param array $record |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | private function mapRecordToDefinitionValue($record) |
||
312 | } |
||
313 |