diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index e5fcd4f768579..7390e4289f510 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -5,8 +5,7 @@ CHANGELOG ----- * added `%env(trim:...)%` processor to trim a string value - * added `%env(default:...)%` processor to fallback to a default value - * added `%env(nullable:...)%` processor to allow empty variables to be processed as null values + * added `%env(default:param_name:...)%` processor to fallback to a parameter or to null when using `%env(default::...)%` * added support for deprecating aliases * made `ContainerParametersResource` final and not implement `Serializable` anymore * added ability to define an index for a tagged collection diff --git a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php index 137fc97798cc3..d734cf5b8fc1d 100644 --- a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php +++ b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php @@ -41,7 +41,6 @@ public static function getProvidedTypes() 'int' => 'int', 'json' => 'array', 'key' => 'bool|int|float|string|array', - 'nullable' => 'bool|int|float|string|array', 'resolve' => 'string', 'default' => 'bool|int|float|string|array', 'string' => 'string', @@ -84,15 +83,21 @@ public function getEnv($prefix, $name, \Closure $getEnv) $next = substr($name, $i + 1); $default = substr($name, 0, $i); - if (!$this->container->hasParameter($default)) { + if ('' !== $default && !$this->container->hasParameter($default)) { throw new RuntimeException(sprintf('Invalid env fallback in "default:%s": parameter "%s" not found.', $name, $default)); } try { - return $getEnv($next); + $env = $getEnv($next); + + if ('' !== $env && null !== $env) { + return $env; + } } catch (EnvNotFoundException $e) { - return $this->container->getParameter($default); + // no-op } + + return '' === $default ? null : $this->container->getParameter($default); } if ('file' === $prefix) { @@ -196,10 +201,6 @@ public function getEnv($prefix, $name, \Closure $getEnv) return str_getcsv($env); } - if ('nullable' === $prefix) { - return '' === $env ? null : $env; - } - if ('trim' === $prefix) { return trim($env); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php index 7d73f6cfb37e9..f376165dfc0a1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php @@ -39,7 +39,6 @@ public function testSimpleProcessor() 'int' => ['int'], 'json' => ['array'], 'key' => ['bool', 'int', 'float', 'string', 'array'], - 'nullable' => ['bool', 'int', 'float', 'string', 'array'], 'resolve' => ['string'], 'default' => ['bool', 'int', 'float', 'string', 'array'], 'string' => ['string'], diff --git a/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php b/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php index 31614ce7d064f..7192127691546 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php @@ -440,7 +440,7 @@ public function testGetEnvKeyChained() public function testGetEnvNullable($value, $processed) { $processor = new EnvVarProcessor(new Container()); - $result = $processor->getEnv('nullable', 'foo', function ($name) use ($value) { + $result = $processor->getEnv('default', ':foo', function ($name) use ($value) { $this->assertSame('foo', $name); return $value; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy