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 Collection |
||
90 | */ |
||
91 | public function getHeaders() |
||
95 | |||
96 | /** |
||
97 | * @return Collection |
||
98 | */ |
||
99 | public function getDefinitions() |
||
103 | |||
104 | /** |
||
105 | * @return Collection |
||
106 | */ |
||
107 | public function getData() |
||
111 | |||
112 | |||
113 | /** |
||
114 | * Validates a string |
||
115 | * @param string $contents |
||
116 | * @return bool Returns true if content is valid |
||
117 | */ |
||
118 | protected function containsValidBLM($contents) |
||
128 | |||
129 | /** |
||
130 | * Verifies if contents contain a headers sections |
||
131 | * @param string $contents |
||
132 | * @return bool |
||
133 | */ |
||
134 | protected function containsHeader($contents) |
||
138 | |||
139 | /** |
||
140 | * Verifies if contents contain a headers sections |
||
141 | * @param string $contents |
||
142 | * @return bool |
||
143 | */ |
||
144 | protected function containsDefinition($contents) |
||
148 | |||
149 | /** |
||
150 | * Verifies if contents contain a headers sections |
||
151 | * @param string $contents |
||
152 | * @return bool |
||
153 | */ |
||
154 | protected function containsData($contents) |
||
158 | |||
159 | /** |
||
160 | * @param string $contents |
||
161 | * @return Reader |
||
162 | */ |
||
163 | protected function parse($contents) |
||
175 | |||
176 | /** |
||
177 | * Parses the #HEADER# section of the BLM file and stores it in $this->headers |
||
178 | * @param string $contents |
||
179 | */ |
||
180 | protected function parseHeader($contents) |
||
199 | |||
200 | /** |
||
201 | * Parses the #DEFINITION# section of the BLM file and stores it in $this->definitions |
||
202 | * @param string $contents |
||
203 | */ |
||
204 | protected function parseDefinition($contents) |
||
222 | |||
223 | /** |
||
224 | * Parses the #DATA# section of the BLM file and stores it in $this->data |
||
225 | * @param $contents |
||
226 | */ |
||
227 | protected function parseData($contents) |
||
249 | |||
250 | /** |
||
251 | * @param $string |
||
252 | * @return VerbalExpressions |
||
253 | */ |
||
254 | private function getRegexFor($string) |
||
262 | |||
263 | /** |
||
264 | * @param $line |
||
265 | * @return bool |
||
266 | */ |
||
267 | private function isValidLineWithoutHash($line) |
||
271 | /** |
||
272 | * @param array $record |
||
273 | * @return array |
||
274 | */ |
||
275 | private function mapRecordToDefinitionValue($record) |
||
287 | } |
||
288 |