1 | <?php |
||
11 | 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 | protected $contents = null; |
||
21 | |||
22 | /** |
||
23 | * @var Collection Parsed header |
||
24 | */ |
||
25 | protected $headers = null; |
||
26 | |||
27 | /** |
||
28 | * @var Collection Parsed definition |
||
29 | */ |
||
30 | protected $definitions = null; |
||
31 | |||
32 | /** |
||
33 | * @var Collection Parsed data |
||
34 | */ |
||
35 | protected $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 | * @return $this |
||
48 | * @throws FileNotFoundException |
||
49 | * @throws InvalidBlmFileException |
||
50 | */ |
||
51 | public function loadFromFile($filePath) |
||
65 | |||
66 | /** |
||
67 | * @param string $contents Contents of a BLM file |
||
68 | * @return Reader |
||
69 | * @throws InvalidBlmFileException |
||
70 | */ |
||
71 | public function loadFromString($contents) |
||
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getRawContents() |
||
87 | |||
88 | /** |
||
89 | * Return array of DATA |
||
90 | * @return array |
||
91 | */ |
||
92 | public function toArray() |
||
99 | |||
100 | /** |
||
101 | * @return Collection |
||
102 | */ |
||
103 | public function getData() |
||
107 | |||
108 | /** |
||
109 | * @return Collection |
||
110 | */ |
||
111 | protected function getHeaders() |
||
115 | |||
116 | /** |
||
117 | * @return Collection |
||
118 | */ |
||
119 | protected function getDefinitions() |
||
123 | |||
124 | |||
125 | /** |
||
126 | * Validates a string |
||
127 | * @param string $contents |
||
128 | * @return bool Returns true if content is valid |
||
129 | */ |
||
130 | protected function containsValidBLM($contents) |
||
140 | |||
141 | /** |
||
142 | * Verifies if contents contain a headers sections |
||
143 | * @param string $contents |
||
144 | * @return bool |
||
145 | */ |
||
146 | protected function containsHeader($contents) |
||
150 | |||
151 | /** |
||
152 | * Verifies if contents contain a headers sections |
||
153 | * @param string $contents |
||
154 | * @return bool |
||
155 | */ |
||
156 | protected function containsDefinition($contents) |
||
160 | |||
161 | /** |
||
162 | * Verifies if contents contain a headers sections |
||
163 | * @param string $contents |
||
164 | * @return bool |
||
165 | */ |
||
166 | protected function containsData($contents) |
||
170 | |||
171 | /** |
||
172 | * @param string $contents |
||
173 | * @return Reader |
||
174 | */ |
||
175 | protected function parse($contents) |
||
187 | |||
188 | /** |
||
189 | * Parses the #HEADER# section of the BLM file and stores it in $this->headers |
||
190 | * @param string $contents |
||
191 | */ |
||
192 | protected function parseHeader($contents) |
||
211 | |||
212 | /** |
||
213 | * Parses the #DEFINITION# section of the BLM file and stores it in $this->definitions |
||
214 | * @param string $contents |
||
215 | */ |
||
216 | protected function parseDefinition($contents) |
||
234 | |||
235 | /** |
||
236 | * Parses the #DATA# section of the BLM file and stores it in $this->data |
||
237 | * @param $contents |
||
238 | */ |
||
239 | protected function parseData($contents) |
||
261 | |||
262 | /** |
||
263 | * @param $string |
||
264 | * @return VerbalExpressions |
||
265 | */ |
||
266 | private function getRegexFor($string) |
||
274 | |||
275 | /** |
||
276 | * @param $line |
||
277 | * @return bool |
||
278 | */ |
||
279 | private function isValidLineWithoutHash($line) |
||
283 | /** |
||
284 | * @param array $record |
||
285 | * @return array |
||
286 | */ |
||
287 | private function mapRecordToDefinitionValue($record) |
||
299 | } |
||
300 |