1 | <?php |
||
2 | |||
3 | // https://github.com/m1/Env/blob/master/src/Parser/ValueParser.php |
||
4 | |||
5 | namespace Codervio\Envmanager\Parser; |
||
6 | |||
7 | use Codervio\Envmanager\Resolver\ArrayStore; |
||
8 | |||
9 | class Parser |
||
10 | { |
||
11 | public $arr; |
||
12 | private $data; |
||
13 | |||
14 | public function __construct() |
||
15 | { |
||
16 | $this->arr = new ArrayStore(); |
||
17 | } |
||
18 | |||
19 | public function prepareLines($input) |
||
20 | { |
||
21 | return str_replace(array('\n', '\r\n', '\r'), PHP_EOL, $input); |
||
22 | } |
||
23 | |||
24 | public function explodeLines($data) |
||
25 | { |
||
26 | $this->data = explode("\n", str_replace(array("\r\n", "\n\r", "\r"), "\n", $data)); |
||
27 | |||
28 | if (is_array($this->data)) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
29 | |||
30 | foreach ($this->data as $key => $val) { |
||
31 | |||
32 | $this->arr->append($val); |
||
33 | |||
34 | $this->cleanLine($key, $val); |
||
35 | |||
36 | } |
||
37 | } else { |
||
38 | return; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | private function cleanLine($key, $line) |
||
43 | { |
||
44 | if (empty($line)) { |
||
45 | $this->arr->offsetUnset($key); |
||
46 | } |
||
47 | } |
||
48 | } |