[DI] Avoid leaking unused env placeholders
This commit is contained in:
parent
671e412417
commit
41f8494722
@ -84,6 +84,8 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
|
||||
} finally {
|
||||
BaseNode::resetPlaceholders();
|
||||
}
|
||||
|
||||
$resolvingBag->clearUnusedEnvPlaceholders();
|
||||
}
|
||||
|
||||
private static function getType($value): string
|
||||
|
@ -87,6 +87,11 @@ class EnvPlaceholderParameterBag extends ParameterBag
|
||||
return $this->unusedEnvPlaceholders;
|
||||
}
|
||||
|
||||
public function clearUnusedEnvPlaceholders()
|
||||
{
|
||||
$this->unusedEnvPlaceholders = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the env placeholders of another EnvPlaceholderParameterBag.
|
||||
*/
|
||||
|
@ -226,7 +226,7 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
|
||||
public function testConfigurationWithoutRootNode(): void
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension($ext = new EnvExtension(new EnvConfigurationWithoutRootNode()));
|
||||
$container->registerExtension(new EnvExtension(new EnvConfigurationWithoutRootNode()));
|
||||
$container->loadFromExtension('env_extension');
|
||||
|
||||
$this->doProcess($container);
|
||||
@ -234,6 +234,21 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testDiscardedEnvInConfig(): void
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('env(BOOLISH)', '1');
|
||||
$container->setParameter('boolish', '%env(BOOLISH)%');
|
||||
$container->registerExtension(new EnvExtension());
|
||||
$container->prependExtensionConfig('env_extension', array(
|
||||
'array_node' => array('bool_force_cast' => '%boolish%'),
|
||||
));
|
||||
|
||||
$container->compile(true);
|
||||
|
||||
$this->assertSame('1', $container->getParameter('boolish'));
|
||||
}
|
||||
|
||||
private function doProcess(ContainerBuilder $container): void
|
||||
{
|
||||
(new MergeExtensionConfigurationPass())->process($container);
|
||||
@ -260,8 +275,19 @@ class EnvConfiguration implements ConfigurationInterface
|
||||
->ifTrue(function ($value) { return !is_array($value); })
|
||||
->then(function ($value) { return array('child_node' => $value); })
|
||||
->end()
|
||||
->beforeNormalization()
|
||||
->ifArray()
|
||||
->then(function (array $v) {
|
||||
if (isset($v['bool_force_cast'])) {
|
||||
$v['bool_force_cast'] = (bool) $v['bool_force_cast'];
|
||||
}
|
||||
|
||||
return $v;
|
||||
})
|
||||
->end()
|
||||
->children()
|
||||
->scalarNode('child_node')->end()
|
||||
->booleanNode('bool_force_cast')->end()
|
||||
->integerNode('int_unset_at_zero')
|
||||
->validate()
|
||||
->ifTrue(function ($value) { return 0 === $value; })
|
||||
|
Reference in New Issue
Block a user