1 | <?php |
||
30 | class ValueParser extends AbstractParser |
||
31 | { |
||
32 | /** |
||
33 | * The trait for checking types |
||
34 | */ |
||
35 | use ValueCheckTrait; |
||
36 | |||
37 | /** |
||
38 | * The regex to get the content between double quote (") strings, ignoring escaped quotes. |
||
39 | * Unescaped: "(?:[^"\\]*(?:\\.)?)*" |
||
40 | * |
||
41 | * @var string REGEX_QUOTE_DOUBLE_STRING |
||
42 | */ |
||
43 | const REGEX_QUOTE_DOUBLE_STRING = '"(?:[^\"\\\\]*(?:\\\\.)?)*\"'; |
||
44 | |||
45 | /** |
||
46 | * The regex to get the content between single quote (') strings, ignoring escaped quotes |
||
47 | * Unescaped: '(?:[^'\\]*(?:\\.)?)*' |
||
48 | * |
||
49 | * @var string REGEX_QUOTE_SINGLE_STRING |
||
50 | */ |
||
51 | const REGEX_QUOTE_SINGLE_STRING = "'(?:[^'\\\\]*(?:\\\\.)?)*'"; |
||
52 | |||
53 | /** |
||
54 | * The bool variants available in .env |
||
55 | * |
||
56 | * @var array $bool_variants |
||
57 | */ |
||
58 | private static $bool_variants = array( |
||
|
|||
59 | 'true', 'false', 'yes', 'no' |
||
60 | ); |
||
61 | |||
62 | /** |
||
63 | * The map to convert escaped characters into real characters |
||
64 | * |
||
65 | * @var array $character_map |
||
66 | */ |
||
67 | private static $character_map = array( |
||
68 | "\\n" => "\n", |
||
69 | "\\\"" => "\"", |
||
70 | '\\\'' => "'", |
||
71 | '\\t' => "\t" |
||
72 | ); |
||
73 | |||
74 | private $variable_parser; |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 57 | public function __construct($parser) |
|
85 | |||
86 | /** |
||
87 | * Parses a .env value |
||
88 | * |
||
89 | * @param string $value The value to parse |
||
90 | * |
||
91 | * @return string|null The parsed key, or null if the key is a comment |
||
92 | */ |
||
93 | 42 | public function parse($value) |
|
103 | |||
104 | /** |
||
105 | * Parses a .env value |
||
106 | * |
||
107 | * @param string $value The value to parse |
||
108 | * |
||
109 | * @return string|null The parsed value, or null if the value is null |
||
110 | */ |
||
111 | 42 | private function parseValue($value) |
|
132 | |||
133 | /** |
||
134 | * Parses a .env string |
||
135 | * |
||
136 | * @param string $value The value to parse |
||
137 | * |
||
138 | * @return string The parsed string |
||
139 | */ |
||
140 | 21 | private function parseString($value) |
|
157 | |||
158 | /** |
||
159 | * Gets the regex matches in the string |
||
160 | * |
||
161 | * @param string $regex The regex to use |
||
162 | * @param string $value The value to parse |
||
163 | * @param string $symbol The symbol we're parsing for |
||
164 | * |
||
165 | * @throws \M1\Env\Exception\ParseException If the string has a missing end quote |
||
166 | * |
||
167 | * @return array The matches based on the regex and the value |
||
168 | */ |
||
169 | 21 | private function fetchStringMatches($value, $regex, $symbol) |
|
183 | /** |
||
184 | * Parses a .env null value |
||
185 | * |
||
186 | * @param string $value The value to parse |
||
187 | * |
||
188 | * @return null Null value |
||
189 | */ |
||
190 | 12 | private function parseNull($value) |
|
194 | |||
195 | /** |
||
196 | * Parses a .env unquoted string |
||
197 | * |
||
198 | * @param string $value The value to parse |
||
199 | * |
||
200 | * @return string The parsed string |
||
201 | */ |
||
202 | 36 | private function parseUnquotedString($value) |
|
210 | |||
211 | /** |
||
212 | * Parses a .env bool |
||
213 | * |
||
214 | * @param string $value The value to parse |
||
215 | * |
||
216 | * @return bool The parsed bool |
||
217 | */ |
||
218 | 12 | private function parseBool($value) |
|
224 | |||
225 | /** |
||
226 | * Parses a .env number |
||
227 | * |
||
228 | * @param string $value The value to parse |
||
229 | * |
||
230 | * @return int|float The parsed bool |
||
231 | */ |
||
232 | 9 | private function parseNumber($value) |
|
240 | |||
241 | /** |
||
242 | * Strips comments from a value |
||
243 | * |
||
244 | * @param string $value The value to strip comments from |
||
245 | * |
||
246 | * @return string value |
||
247 | */ |
||
248 | 39 | private function stripComments($value) |
|
252 | } |
||
253 |
This check marks private properties in classes that are never used. Those properties can be removed.