1 | <?php |
||
29 | class ValueParser extends AbstractParser |
||
30 | { |
||
31 | /** |
||
32 | * The trait for checking types |
||
33 | */ |
||
34 | use ValueTypeCheckable; |
||
35 | |||
36 | /** |
||
37 | * The regex to get variables '$(VARIABLE)' in .env |
||
38 | * Unescaped: ${(.*?)} |
||
39 | * |
||
40 | * @var string REGEX_ENV_VARIABLE |
||
41 | */ |
||
42 | const REGEX_ENV_VARIABLE = '\\${(.*?)}'; |
||
43 | |||
44 | /** |
||
45 | * The regex to get the content between double quote (") strings, ignoring escaped quotes. |
||
46 | * Unescaped: "(?:[^"\\]*(?:\\.)?)*" |
||
47 | * |
||
48 | * @var string REGEX_QUOTE_DOUBLE_STRING |
||
49 | */ |
||
50 | const REGEX_QUOTE_DOUBLE_STRING = '"(?:[^\"\\\\]*(?:\\\\.)?)*\"'; |
||
51 | |||
52 | /** |
||
53 | * The regex to get the content between single quote (') strings, ignoring escaped quotes |
||
54 | * Unescaped: '(?:[^'\\]*(?:\\.)?)*' |
||
55 | * |
||
56 | * @var string REGEX_QUOTE_SINGLE_STRING |
||
57 | */ |
||
58 | const REGEX_QUOTE_SINGLE_STRING = "'(?:[^'\\\\]*(?:\\\\.)?)*'"; |
||
59 | |||
60 | /** |
||
61 | * The bool variants available in .env |
||
62 | * |
||
63 | * @var array $bool_variants |
||
64 | */ |
||
65 | private static $bool_variants = array( |
||
|
|||
66 | 'true', 'false', 'yes', 'no' |
||
67 | ); |
||
68 | |||
69 | /** |
||
70 | * The map to convert escaped characters into real characters |
||
71 | * |
||
72 | * @var array $character_map |
||
73 | */ |
||
74 | private static $character_map = array( |
||
75 | "\\n" => "\n", |
||
76 | "\\\"" => "\"", |
||
77 | '\\\'' => "'", |
||
78 | '\\t' => "\t" |
||
79 | ); |
||
80 | |||
81 | /** |
||
82 | * The line num of the current value |
||
83 | * |
||
84 | * @var int $line_num |
||
85 | */ |
||
86 | private $line_num; |
||
87 | |||
88 | /** |
||
89 | * The current parsed values/lines |
||
90 | * |
||
91 | * @var array $lines |
||
92 | */ |
||
93 | private $lines; |
||
94 | |||
95 | /** |
||
96 | * Parses a .env value |
||
97 | * |
||
98 | * @param string $value The value to parse |
||
99 | * @param array $lines The array of already parsed lines |
||
100 | * @param int $line_num The line num of the value |
||
101 | * |
||
102 | * @return string|null The parsed key, or null if the key is a comment |
||
103 | */ |
||
104 | 30 | public function parse($value, $lines, $line_num) |
|
117 | |||
118 | /** |
||
119 | * Parses a .env value |
||
120 | * |
||
121 | * @param string $value The value to parse |
||
122 | * |
||
123 | * @return string|null The parsed value, or null if the value is null |
||
124 | */ |
||
125 | 30 | private function parseValue($value) |
|
146 | |||
147 | /** |
||
148 | * Parses a .env variable |
||
149 | * |
||
150 | * @param string $value The value to parse |
||
151 | * @param bool $quoted_string Is the value in a quoted string |
||
152 | * |
||
153 | * @return string The parsed value |
||
154 | */ |
||
155 | 21 | private function parseVariables($value, $quoted_string = false) |
|
178 | |||
179 | /** |
||
180 | * Get variable matches inside a string |
||
181 | * |
||
182 | * @param string $value The value to parse |
||
183 | * |
||
184 | * @return array The variable matches |
||
185 | */ |
||
186 | 21 | private function fetchVariableMatches($value) |
|
196 | |||
197 | /** |
||
198 | * Parses a .env variable |
||
199 | * |
||
200 | * @param string $value The value to parse |
||
201 | * @param string $variable_name The variable name to get |
||
202 | * @param array $matches The matches of the variables |
||
203 | * @param bool $quoted_string Is the value in a quoted string |
||
204 | * |
||
205 | * @throws \M1\Env\Exception\ParseException If the variable can not be found |
||
206 | * |
||
207 | * @return string The parsed value |
||
208 | */ |
||
209 | 6 | private function fetchVariable($value, $variable_name, $matches, $quoted_string) |
|
231 | |||
232 | /** |
||
233 | * Parses a .env string |
||
234 | * |
||
235 | * @param string $value The value to parse |
||
236 | * |
||
237 | * @throws \M1\Env\Exception\ParseException If the string has a missing end quote |
||
238 | * |
||
239 | * @return string The parsed string |
||
240 | */ |
||
241 | 12 | private function parseString($value) |
|
266 | |||
267 | /** |
||
268 | * Parses a .env null value |
||
269 | * |
||
270 | * @param string $value The value to parse |
||
271 | * |
||
272 | * @return null Null value |
||
273 | */ |
||
274 | 3 | private function parseNull($value) |
|
278 | |||
279 | /** |
||
280 | * Parses a .env unquoted string |
||
281 | * |
||
282 | * @param string $value The value to parse |
||
283 | * |
||
284 | * @return string The parsed string |
||
285 | */ |
||
286 | 24 | private function parseUnquotedString($value) |
|
294 | |||
295 | /** |
||
296 | * Parses a .env bool |
||
297 | * |
||
298 | * @param string $value The value to parse |
||
299 | * |
||
300 | * @return bool The parsed bool |
||
301 | */ |
||
302 | 6 | private function parseBool($value) |
|
318 | |||
319 | /** |
||
320 | * Parses a .env number |
||
321 | * |
||
322 | * @param string $value The value to parse |
||
323 | * |
||
324 | * @return int|float The parsed bool |
||
325 | */ |
||
326 | 6 | private function parseNumber($value) |
|
334 | |||
335 | /** |
||
336 | * Strips comments from a value |
||
337 | * |
||
338 | * @param string $value The value to strip comments from |
||
339 | * |
||
340 | * @return string value |
||
341 | */ |
||
342 | 27 | private function stripComments($value) |
|
346 | } |
This check marks private properties in classes that are never used. Those properties can be removed.