diff --git a/src/Symfony/Component/Config/Definition/BaseNode.php b/src/Symfony/Component/Config/Definition/BaseNode.php index 56480eb99c..2cae80e7e0 100644 --- a/src/Symfony/Component/Config/Definition/BaseNode.php +++ b/src/Symfony/Component/Config/Definition/BaseNode.php @@ -476,6 +476,14 @@ abstract class BaseNode implements NodeInterface return true; } + /** + * Tests if a placeholder is being handled currently. + */ + protected function isHandlingPlaceholder(): bool + { + return null !== $this->handlingPlaceholder; + } + /** * Gets allowed dynamic types for this node. */ diff --git a/src/Symfony/Component/Config/Definition/ScalarNode.php b/src/Symfony/Component/Config/Definition/ScalarNode.php index b3b387c62b..5d4fe17373 100644 --- a/src/Symfony/Component/Config/Definition/ScalarNode.php +++ b/src/Symfony/Component/Config/Definition/ScalarNode.php @@ -52,6 +52,10 @@ class ScalarNode extends VariableNode */ protected function isValueEmpty($value) { + if ($this->isHandlingPlaceholder()) { + return false; + } + return null === $value || '' === $value; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php index a241a8f5b8..0ff30a2eac 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php @@ -196,6 +196,19 @@ class ValidateEnvPlaceholdersPassTest extends TestCase $this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig())); } + public function testEmptyEnvWithCannotBeEmptyForScalarNode(): void + { + $container = new ContainerBuilder(); + $container->registerExtension($ext = new EnvExtension()); + $container->prependExtensionConfig('env_extension', $expected = array( + 'scalar_node_not_empty' => '%env(SOME)%', + )); + + $this->doProcess($container); + + $this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig())); + } + private function doProcess(ContainerBuilder $container): void { (new MergeExtensionConfigurationPass())->process($container); @@ -213,6 +226,7 @@ class EnvConfiguration implements ConfigurationInterface $rootNode ->children() ->scalarNode('scalar_node')->end() + ->scalarNode('scalar_node_not_empty')->cannotBeEmpty()->end() ->integerNode('int_node')->end() ->floatNode('float_node')->end() ->booleanNode('bool_node')->end()