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 content to parse |
||
73 | * @param array $context Variables context |
||
74 | */ |
||
75 | 66 | public function __construct($content, array $context = array()) |
|
83 | |||
84 | /** |
||
85 | * Parses the .env and returns the contents statically |
||
86 | * |
||
87 | * @param string $content The content to parse |
||
88 | * @param array $context Variables context |
||
89 | * |
||
90 | * @return array The .env contents |
||
91 | */ |
||
92 | 66 | public static function parse($content, array $context = array()) |
|
98 | |||
99 | /** |
||
100 | * Opens the .env, parses it then returns the contents |
||
101 | * |
||
102 | * @param string $content The content to parse |
||
103 | * |
||
104 | * @return array The .env contents |
||
105 | */ |
||
106 | 66 | protected function doParse($content) |
|
116 | |||
117 | /** |
||
118 | * Splits the string into an array |
||
119 | * |
||
120 | * @param string $content The string content to split |
||
121 | * |
||
122 | * @return array The array of lines to parse |
||
123 | */ |
||
124 | 66 | private function makeLines($content) |
|
128 | |||
129 | /** |
||
130 | * Parses the .env line by line |
||
131 | * |
||
132 | * @param array $raw_lines The raw content of the file |
||
133 | * |
||
134 | * @throws \M1\Env\Exception\ParseException If the file does not have a key=value structure |
||
135 | * |
||
136 | * @return array The .env contents |
||
137 | */ |
||
138 | 60 | private function parseContent(array $raw_lines) |
|
157 | |||
158 | /** |
||
159 | * Parses a line of the .env |
||
160 | * |
||
161 | * @param string $raw_line The raw content of the line |
||
162 | * |
||
163 | * @return array The parsed lines |
||
164 | */ |
||
165 | 60 | private function parseLine($raw_line) |
|
179 | |||
180 | /** |
||
181 | * Parses a export line of the .env |
||
182 | * |
||
183 | * @param string $raw_line The raw content of the line |
||
184 | * |
||
185 | * @throws \M1\Env\Exception\ParseException If the file does not have a key=value structure |
||
186 | * |
||
187 | * @return string The parsed line |
||
188 | */ |
||
189 | 60 | private function parseExport($raw_line) |
|
209 | |||
210 | /** |
||
211 | * Gets the key = value items from the line |
||
212 | * |
||
213 | * @param string $raw_line The raw content of the line |
||
214 | * |
||
215 | * @throws \M1\Env\Exception\ParseException If the line does not have a key=value structure |
||
216 | * |
||
217 | * @return array The parsed lines |
||
218 | */ |
||
219 | 57 | private function parseKeyValue($raw_line) |
|
233 | |||
234 | /** |
||
235 | * Returns the contents of the .env |
||
236 | * |
||
237 | * @return array The .env contents |
||
238 | */ |
||
239 | 45 | public function getContent($keyName = null) |
|
246 | } |
||
247 |