1 | <?php |
||
31 | class Parser |
||
32 | { |
||
33 | /** |
||
34 | * The Env key parser |
||
35 | * |
||
36 | * @var \M1\Env\Parser\KeyParser $key_parser |
||
37 | */ |
||
38 | private $key_parser; |
||
39 | |||
40 | /** |
||
41 | * The line num of the current value |
||
42 | * |
||
43 | * @var int $line_num |
||
44 | */ |
||
45 | public $line_num; |
||
46 | |||
47 | /** |
||
48 | * The current parsed values/lines |
||
49 | * |
||
50 | * @var array $lines |
||
51 | */ |
||
52 | public $lines = array(); |
||
53 | |||
54 | /** |
||
55 | * The String helper class |
||
56 | * |
||
57 | * @var \M1\Env\Helper\StringHelper $string_helper |
||
58 | */ |
||
59 | public $string_helper; |
||
60 | |||
61 | |||
62 | /** |
||
63 | * The Env value parser |
||
64 | * |
||
65 | * @var \M1\Env\Parser\ValueParser $value_parser |
||
66 | */ |
||
67 | public $value_parser; |
||
68 | |||
69 | /** |
||
70 | * The parser constructor |
||
71 | * |
||
72 | * @param string $content The |
||
73 | */ |
||
74 | 63 | public function __construct($content) |
|
82 | |||
83 | /** |
||
84 | * Parses the .env and returns the contents statically |
||
85 | * |
||
86 | * @param string $content The content to parse |
||
87 | * |
||
88 | * @return array The .env contents |
||
89 | */ |
||
90 | 63 | public static function parse($content) |
|
96 | |||
97 | /** |
||
98 | * Opens the .env, parses it then returns the contents |
||
99 | * |
||
100 | * @param string $content The content to parse |
||
101 | * |
||
102 | * @return array The .env contents |
||
103 | */ |
||
104 | 63 | private function doParse($content) |
|
114 | |||
115 | /** |
||
116 | * Splits the string into an array |
||
117 | * |
||
118 | * @param string $content The string content to split |
||
119 | * |
||
120 | * @return array The array of lines to parse |
||
121 | */ |
||
122 | 63 | private function makeLines($content) |
|
126 | |||
127 | /** |
||
128 | * Parses the .env line by line |
||
129 | * |
||
130 | * @param array $raw_lines The raw content of the file |
||
131 | * |
||
132 | * @throws \M1\Env\Exception\ParseException If the file does not have a key=value structure |
||
133 | * |
||
134 | * @return array The .env contents |
||
135 | */ |
||
136 | 57 | private function parseContent(array $raw_lines) |
|
153 | |||
154 | /** |
||
155 | * Parses a line of the .env |
||
156 | * |
||
157 | * @param string $raw_line The raw content of the line |
||
158 | * |
||
159 | * @return array The parsed lines |
||
160 | */ |
||
161 | 57 | private function parseLine($raw_line) |
|
175 | |||
176 | /** |
||
177 | * Parses a export line of the .env |
||
178 | * |
||
179 | * @param string $raw_line The raw content of the line |
||
180 | * |
||
181 | * @throws \M1\Env\Exception\ParseException If the file does not have a key=value structure |
||
182 | * |
||
183 | * @return string The parsed line |
||
184 | */ |
||
185 | 57 | private function parseExport($raw_line) |
|
205 | |||
206 | /** |
||
207 | * Gets the key = value items from the line |
||
208 | * |
||
209 | * @param string $raw_line The raw content of the line |
||
210 | * |
||
211 | * @throws \M1\Env\Exception\ParseException If the line does not have a key=value structure |
||
212 | * |
||
213 | * @return array The parsed lines |
||
214 | */ |
||
215 | 54 | private function parseKeyValue($raw_line) |
|
229 | |||
230 | /** |
||
231 | * Returns the contents of the .env |
||
232 | * |
||
233 | * @return array The .env contents |
||
234 | */ |
||
235 | 42 | public function getContent() |
|
239 | } |
||
240 |