diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index a0ad77edd0796..607f1d1fe743d 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -226,7 +226,9 @@ public function canBeEnabled() ->beforeNormalization() ->ifArray() ->then(function ($v) { - $v['enabled'] = isset($v['enabled']) ? $v['enabled'] : true; + if (!isset($v['enabled'])) { + $v['enabled'] = !empty($v); + } return $v; }) diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index 16a38c30b0f9d..4b6f4d7fd1013 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -207,6 +207,20 @@ public function testCanBeDisabled() $this->assertTrue($this->getField($enabledNode, 'defaultValue')); } + public function testEnableableNodeIsDisabledForEmptyConfigurationWhenNormalized() + { + $config = array(); + + $node = new ArrayNodeDefinition('root'); + $node->canBeEnabled(); + + $this->assertEquals( + array('enabled' => false), + $node->getNode()->normalize($config), + 'An enableable node is disabled by default' + ); + } + public function testIgnoreExtraKeys() { $node = new ArrayNodeDefinition('root'); @@ -240,6 +254,7 @@ public function getEnableableNodeFixtures() array(array('enabled' => true, 'foo' => 'baz'), array(array('foo' => 'baz')), 'any configuration enables an enableable node'), array(array('enabled' => false, 'foo' => 'baz'), array(array('foo' => 'baz', 'enabled' => false)), 'An enableable node can be disabled'), array(array('enabled' => false, 'foo' => 'bar'), array(false), 'false disables an enableable node'), + array(array('enabled' => false, 'foo' => 'bar'), array(), 'enableable node is disabled by default'), ); } diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php index 0a9312346e989..6e99469a4e48c 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Config\Tests\Definition\Builder; use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder; use Symfony\Component\Config\Definition\Builder\TreeBuilder; @@ -131,4 +132,22 @@ public function testDefinitionExampleGetsTransferredToNode() $this->assertInternalType('array', $tree->getExample()); $this->assertEquals('example', $children['child']->getExample()); } + + public function testRootNodeThatCanBeEnabledIsDisabledByDefault() + { + $builder = new TreeBuilder(); + + $builder->root('test') + ->canBeEnabled(); + + $tree = $builder->buildTree(); + $children = $tree->getChildren(); + + $this->assertFalse($children['enabled']->getDefaultValue()); + + $processor = new Processor(); + $result = $processor->process($tree, array()); + + $this->assertEquals(array('enabled' => false), $result); + } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index b6b9e93a86ca3..c548ed459c0c7 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -425,6 +425,10 @@ private function loadFromExtensions(array $content) continue; } + if (null === $values) { + $values = array('enabled' => null); + } + if (!is_array($values)) { $values = array(); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooConfiguration.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooConfiguration.php new file mode 100644 index 0000000000000..e37bef3e15640 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooConfiguration.php @@ -0,0 +1,15 @@ +root('foo'); + $rootNode->canBeEnabled(); + + return $builder; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooExtension.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooExtension.php new file mode 100644 index 0000000000000..e4ff380416f38 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooExtension.php @@ -0,0 +1,19 @@ +processConfiguration(new \FooConfiguration(), $configs); + + $container->setParameter('foo_extension_enabled', $config['enabled']); + } + + public function getAlias() + { + return 'foo'; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/extension_nullable.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/extension_nullable.yml new file mode 100644 index 0000000000000..b5051d957328d --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/extension_nullable.yml @@ -0,0 +1 @@ +foo: ~ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 85c74b572d080..fdc3ffab7e412 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -31,6 +31,8 @@ public static function setUpBeforeClass() self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); require_once self::$fixturesPath.'/includes/foo.php'; require_once self::$fixturesPath.'/includes/ProjectExtension.php'; + require_once self::$fixturesPath.'/includes/FooExtension.php'; + require_once self::$fixturesPath.'/includes/FooConfiguration.php'; } /** @@ -207,6 +209,19 @@ public function testExtensions() } } + public function testNullableExtension() + { + $container = new ContainerBuilder(); + $container->registerExtension(new \FooExtension()); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('extension_nullable.yml'); + $container->compile(); + + $isEnabled = $container->getParameter('foo_extension_enabled'); + + $this->assertTrue($isEnabled); + } + public function testSupports() { $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator()); 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