1 | <?php |
||
28 | class ValueParser extends AbstractParser |
||
29 | { |
||
30 | /** |
||
31 | * The regex to get the content between double quote (") strings, ignoring escaped quotes. |
||
32 | * Unescaped: "(?:[^"\\]*(?:\\.)?)*" |
||
33 | * |
||
34 | * @var string REGEX_QUOTE_DOUBLE_STRING |
||
35 | */ |
||
36 | const REGEX_QUOTE_DOUBLE_STRING = '"(?:[^\"\\\\]*(?:\\\\.)?)*\"'; |
||
37 | |||
38 | /** |
||
39 | * The regex to get the content between single quote (') strings, ignoring escaped quotes |
||
40 | * Unescaped: '(?:[^'\\]*(?:\\.)?)*' |
||
41 | * |
||
42 | * @var string REGEX_QUOTE_SINGLE_STRING |
||
43 | */ |
||
44 | const REGEX_QUOTE_SINGLE_STRING = "'(?:[^'\\\\]*(?:\\\\.)?)*'"; |
||
45 | |||
46 | /** |
||
47 | * The value types that Env supports |
||
48 | * |
||
49 | * @var array $value_types |
||
50 | */ |
||
51 | private static $value_types = array( |
||
52 | 'string', |
||
53 | 'bool', |
||
54 | 'number', |
||
55 | 'null', |
||
56 | ); |
||
57 | |||
58 | /** |
||
59 | * The map to convert escaped characters into real characters |
||
60 | * |
||
61 | * @var array $character_map |
||
62 | */ |
||
63 | private static $character_map = array( |
||
64 | "\\n" => "\n", |
||
65 | "\\\"" => "\"", |
||
66 | '\\\'' => "'", |
||
67 | '\\t' => "\t" |
||
68 | ); |
||
69 | |||
70 | /** |
||
71 | * The parser for variables |
||
72 | * |
||
73 | * @var \M1\Env\Parser\VariableParser $variable_parser |
||
74 | */ |
||
75 | private $variable_parser; |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | * |
||
80 | * @param \M1\Env\Parser $parser The parent parser |
||
81 | */ |
||
82 | 57 | public function __construct($parser) |
|
88 | |||
89 | /** |
||
90 | * Parses a .env value |
||
91 | * |
||
92 | * @param string $value The value to parse |
||
93 | * |
||
94 | * @return string|null The parsed key, or null if the key is a comment |
||
95 | */ |
||
96 | 42 | public function parse($value) |
|
106 | |||
107 | /** |
||
108 | * Parses a .env value |
||
109 | * |
||
110 | * @param string $value The value to parse |
||
111 | * |
||
112 | * @return string|null The parsed value, or null if the value is null |
||
113 | * |
||
114 | * @uses parseString |
||
115 | * @uses parseNull |
||
116 | * @uses parseBool |
||
117 | * @uses parseNumber |
||
118 | */ |
||
119 | 42 | private function parseValue($value) |
|
137 | |||
138 | /** |
||
139 | * Gets the functions for the value type |
||
140 | * |
||
141 | * @param string $type The value type |
||
142 | * |
||
143 | * @return string[] The is and parse function names |
||
144 | */ |
||
145 | 42 | private function fetchFunctionNames($type) |
|
154 | |||
155 | /** |
||
156 | * Parses a .env string |
||
157 | * |
||
158 | * @param string $value The value to parse |
||
159 | * |
||
160 | * @return string The parsed string |
||
161 | */ |
||
162 | 21 | private function parseString($value) |
|
179 | |||
180 | /** |
||
181 | * Gets the regex matches in the string |
||
182 | * |
||
183 | * @param string $regex The regex to use |
||
184 | * @param string $value The value to parse |
||
185 | * @param string $symbol The symbol we're parsing for |
||
186 | * |
||
187 | * @throws \M1\Env\Exception\ParseException If the string has a missing end quote |
||
188 | * |
||
189 | * @return string[] The matches based on the regex and the value |
||
190 | */ |
||
191 | 21 | private function fetchStringMatches($value, $regex, $symbol) |
|
205 | |||
206 | /** |
||
207 | * Parses a .env null value |
||
208 | * |
||
209 | * @param string $value The value to parse |
||
210 | * |
||
211 | * @return null Null value |
||
212 | */ |
||
213 | 12 | private function parseNull($value) |
|
217 | |||
218 | /** |
||
219 | * Parses a .env unquoted string |
||
220 | * |
||
221 | * @param string $value The value to parse |
||
222 | * |
||
223 | * @return string The parsed string |
||
224 | */ |
||
225 | 36 | private function parseUnquotedString($value) |
|
233 | |||
234 | /** |
||
235 | * Parses a .env bool |
||
236 | * |
||
237 | * @param string $value The value to parse |
||
238 | * |
||
239 | * @return bool The parsed bool |
||
240 | */ |
||
241 | 12 | private function parseBool($value) |
|
247 | |||
248 | /** |
||
249 | * Parses a .env number |
||
250 | * |
||
251 | * @param string $value The value to parse |
||
252 | * |
||
253 | * @return int|float The parsed bool |
||
254 | */ |
||
255 | 9 | private function parseNumber($value) |
|
263 | } |
||
264 |