|
19 | 19 | * - booleans |
20 | 20 | * - nulls |
21 | 21 | * - single-dimension arrays |
| 22 | + * - default values in env function calls |
22 | 23 | * |
23 | 24 | * To do: |
24 | 25 | * - When an entry does not exist, provide a way to create it |
@@ -87,14 +88,15 @@ protected function parseContentValue(string $contents, string $path, $value): st |
87 | 88 | $replaceValue = $this->writeValueToPhp($value); |
88 | 89 |
|
89 | 90 | $count = 0; |
90 | | - $patterns = []; |
91 | | - $patterns[] = $this->buildStringExpression($key, $items); |
92 | | - $patterns[] = $this->buildStringExpression($key, $items, '"'); |
93 | | - $patterns[] = $this->buildConstantExpression($key, $items); |
94 | | - $patterns[] = $this->buildArrayExpression($key, $items); |
| 91 | + $patterns = array(); |
| 92 | + $patterns[$this->buildStringExpression($key, $items)] = '${1}${2}'.$replaceValue; |
| 93 | + $patterns[$this->buildStringExpression($key, $items, '"')] = '${1}${2}'.$replaceValue; |
| 94 | + $patterns[$this->buildEnvCallExpression($key, $items)] = '${1}${2}${4}' . $replaceValue . '${8}'; |
| 95 | + $patterns[$this->buildConstantExpression($key, $items)] = '${1}${2}'.$replaceValue; |
| 96 | + $patterns[$this->buildArrayExpression($key, $items)] = '${1}${2}'.$replaceValue; |
95 | 97 |
|
96 | | - foreach ($patterns as $pattern) { |
97 | | - $result = preg_replace($pattern, '${1}${2}' . $replaceValue, $result, 1, $count); |
| 98 | + foreach ($patterns as $pattern => $patternReplacement) { |
| 99 | + $result = preg_replace($pattern, $patternReplacement, $result, 1, $count); |
98 | 100 |
|
99 | 101 | if ($count > 0) { |
100 | 102 | break; |
@@ -164,6 +166,22 @@ protected function buildStringExpression(string $targetKey, array $arrayItems = |
164 | 166 | return '/' . implode('', $expression) . '/'; |
165 | 167 | } |
166 | 168 |
|
| 169 | + protected function buildEnvCallExpression(string $targetKey, array $arrayItems = []) |
| 170 | + { |
| 171 | + $expression = array(); |
| 172 | + |
| 173 | + // Opening expression for array items ($1) |
| 174 | + $expression[] = $this->buildArrayOpeningExpression($arrayItems); |
| 175 | + |
| 176 | + // The target key opening |
| 177 | + $expression[] = '(([\'"])' . $targetKey . '\3\s*=>\s*)'; |
| 178 | + |
| 179 | + // The method call |
| 180 | + $expression[] = '(env\(([\'"]).*\5,\s*)([\'"])(.*)\6(\))'; |
| 181 | + |
| 182 | + return '/' . implode('', $expression) . '/'; |
| 183 | + } |
| 184 | + |
167 | 185 | /** |
168 | 186 | * Common constants only (true, false, null, integers) |
169 | 187 | */ |
|
0 commit comments