1 | <?php |
||
8 | class EnvFile |
||
9 | { |
||
10 | /** |
||
11 | * @var \SplFileObject|null |
||
12 | */ |
||
13 | protected $file; |
||
14 | |||
15 | /** |
||
16 | * @param string $path |
||
17 | */ |
||
18 | 10 | public function __construct($path) |
|
22 | |||
23 | /** |
||
24 | * Write content to the file. |
||
25 | * |
||
26 | * @param string $content |
||
27 | * |
||
28 | * @return self |
||
29 | */ |
||
30 | 7 | public function write($content) |
|
38 | |||
39 | /** |
||
40 | * Check if the file is NOT empty. |
||
41 | * |
||
42 | * @return bool |
||
43 | */ |
||
44 | 10 | public function isNotEmpty() |
|
45 | { |
||
46 | 10 | return $this->file->getSize() > 0; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Convert the file values into an associative array. |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | 4 | public function toArray() |
|
58 | |||
59 | /** |
||
60 | * Close the file buffer. |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | 10 | public function close() |
|
68 | |||
69 | /** |
||
70 | * Extract lines from the file. |
||
71 | * |
||
72 | * @return array |
||
73 | */ |
||
74 | 4 | private function linesFromFile() |
|
81 | |||
82 | /** |
||
83 | * Convert config line into key value pairs. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | 4 | private function convertLineValuesToArray() |
|
93 | |||
94 | /** |
||
95 | * Map config line extraction into key value pairs. |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | 4 | private function mapLineValuesAndKeys() |
|
109 | } |
||
110 |