Skip to content

Commit

Permalink
yaml config env var spec conformance (#1486)
Browse files Browse the repository at this point in the history
* add support for env: prefix in yaml config
* align test to example in spec
* do not recursively replace env vars
  - fix env substitution normalization so that it doesn't apply 2 replacement normalizers for string nodes
  • Loading branch information
brettmc authored Jan 28, 2025
1 parent ef5e687 commit a35a1e5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Configuration/Internal/EnvSubstitutionNormalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ private function doApply(NodeDefinition $node): void
default => FILTER_DEFAULT,
};
$node->beforeNormalization()->ifString()->then(fn (string $v) => $this->replaceEnvVariables($v, $filter))->end();
}
if ($node instanceof VariableNodeDefinition) {
} elseif ($node instanceof VariableNodeDefinition) {
$node->beforeNormalization()->always($this->replaceEnvVariablesRecursive(...))->end();
}

Expand All @@ -65,7 +64,7 @@ private function doApply(NodeDefinition $node): void
private function replaceEnvVariables(string $value, int $filter = FILTER_DEFAULT): mixed
{
$replaced = preg_replace_callback(
'/\$\{(?<ENV_NAME>[a-zA-Z_]\w*)(?::-(?<DEFAULT_VALUE>[^\n]*))?}/',
'/\$\{(?:env:)?(?<ENV_NAME>[a-zA-Z_]\w*)(?::-(?<DEFAULT_VALUE>[^\n]*))?}/',
fn (array $matches): string => $this->envReader->read($matches['ENV_NAME']) ?? $matches['DEFAULT_VALUE'] ?? '',
$value,
-1,
Expand Down

0 comments on commit a35a1e5

Please sign in to comment.