From 41f8494722b98d51a92f7c1516ed16fa0c93503b Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Fri, 22 Jun 2018 11:28:46 +0200 Subject: [PATCH] [DI] Avoid leaking unused env placeholders --- .../Compiler/ValidateEnvPlaceholdersPass.php | 2 ++ .../EnvPlaceholderParameterBag.php | 5 ++++ .../ValidateEnvPlaceholdersPassTest.php | 28 ++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php index 58fc95b5fc55c..402aca6378b63 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php @@ -84,6 +84,8 @@ public function process(ContainerBuilder $container) } finally { BaseNode::resetPlaceholders(); } + + $resolvingBag->clearUnusedEnvPlaceholders(); } private static function getType($value): string diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php index 3c68af031f406..20fc77c8b4693 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php @@ -87,6 +87,11 @@ public function getUnusedEnvPlaceholders(): array return $this->unusedEnvPlaceholders; } + public function clearUnusedEnvPlaceholders() + { + $this->unusedEnvPlaceholders = array(); + } + /** * Merges the env placeholders of another EnvPlaceholderParameterBag. */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php index 0fb2f6dc91a43..b5841f343a4e8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php @@ -226,7 +226,7 @@ public function testEnvWithVariableNode(): void 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 @@ public function testConfigurationWithoutRootNode(): void $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 @@ public function getConfigTreeBuilder() ->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; }) 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