From a35a1e51dc61fa2c555e380d21224d363e1b2d01 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Tue, 28 Jan 2025 12:37:53 +1100 Subject: [PATCH] yaml config env var spec conformance (#1486) * 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 --- Configuration/Internal/EnvSubstitutionNormalization.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Configuration/Internal/EnvSubstitutionNormalization.php b/Configuration/Internal/EnvSubstitutionNormalization.php index cfe0bf9..72008b8 100644 --- a/Configuration/Internal/EnvSubstitutionNormalization.php +++ b/Configuration/Internal/EnvSubstitutionNormalization.php @@ -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(); } @@ -65,7 +64,7 @@ private function doApply(NodeDefinition $node): void private function replaceEnvVariables(string $value, int $filter = FILTER_DEFAULT): mixed { $replaced = preg_replace_callback( - '/\$\{(?[a-zA-Z_]\w*)(?::-(?[^\n]*))?}/', + '/\$\{(?:env:)?(?[a-zA-Z_]\w*)(?::-(?[^\n]*))?}/', fn (array $matches): string => $this->envReader->read($matches['ENV_NAME']) ?? $matches['DEFAULT_VALUE'] ?? '', $value, -1,