[DI][Config] Fix empty env validation
This commit is contained in:
parent
e973f6f380
commit
d40a4f409d
@ -476,6 +476,14 @@ abstract class BaseNode implements NodeInterface
|
|||||||
return true;
|
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.
|
* Gets allowed dynamic types for this node.
|
||||||
*/
|
*/
|
||||||
|
@ -52,6 +52,10 @@ class ScalarNode extends VariableNode
|
|||||||
*/
|
*/
|
||||||
protected function isValueEmpty($value)
|
protected function isValueEmpty($value)
|
||||||
{
|
{
|
||||||
|
if ($this->isHandlingPlaceholder()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return null === $value || '' === $value;
|
return null === $value || '' === $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,6 +196,19 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
|
|||||||
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
|
$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
|
private function doProcess(ContainerBuilder $container): void
|
||||||
{
|
{
|
||||||
(new MergeExtensionConfigurationPass())->process($container);
|
(new MergeExtensionConfigurationPass())->process($container);
|
||||||
@ -213,6 +226,7 @@ class EnvConfiguration implements ConfigurationInterface
|
|||||||
$rootNode
|
$rootNode
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('scalar_node')->end()
|
->scalarNode('scalar_node')->end()
|
||||||
|
->scalarNode('scalar_node_not_empty')->cannotBeEmpty()->end()
|
||||||
->integerNode('int_node')->end()
|
->integerNode('int_node')->end()
|
||||||
->floatNode('float_node')->end()
|
->floatNode('float_node')->end()
|
||||||
->booleanNode('bool_node')->end()
|
->booleanNode('bool_node')->end()
|
||||||
|
Reference in New Issue
Block a user