[Config] remove the root method and the nullable name

This commit is contained in:
Amrouche Hamza 2019-06-07 14:26:21 +02:00
parent 1af3952914
commit 7c66e6f1c4
No known key found for this signature in database
GPG Key ID: E45A3DA456145BC1
4 changed files with 10 additions and 50 deletions

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
5.0.0
-----
* Dropped support for constructing a `TreeBuilder` without passing root node information.
* Removed the `root()` method in `TreeBuilder`, pass the root node information to the constructor instead
4.3.0
-----

View File

@ -24,36 +24,10 @@ class TreeBuilder implements NodeParentInterface
protected $tree;
protected $root;
public function __construct(string $name = null, string $type = 'array', NodeBuilder $builder = null)
public function __construct(string $name, string $type = 'array', NodeBuilder $builder = null)
{
if (null === $name) {
@trigger_error('A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0.', E_USER_DEPRECATED);
} else {
$builder = $builder ?: new NodeBuilder();
$this->root = $builder->node($name, $type)->setParent($this);
}
}
/**
* Creates the root node.
*
* @param string $name The name of the root node
* @param string $type The type of the root node
* @param NodeBuilder $builder A custom node builder instance
*
* @return ArrayNodeDefinition|NodeDefinition The root node (as an ArrayNodeDefinition when the type is 'array')
*
* @throws \RuntimeException When the node type is not supported
*
* @deprecated since Symfony 4.3, pass the root name to the constructor instead
*/
public function root($name, $type = 'array', NodeBuilder $builder = null)
{
@trigger_error(sprintf('The "%s()" method called for the "%s" configuration is deprecated since Symfony 4.3, pass the root name to the constructor instead.', __METHOD__, $name), E_USER_DEPRECATED);
$builder = $builder ?: new NodeBuilder();
return $this->root = $builder->node($name, $type)->setParent($this);
$this->root = $builder->node($name, $type)->setParent($this);
}
/**

View File

@ -188,23 +188,4 @@ class TreeBuilderTest extends TestCase
$this->assertInstanceOf('Symfony\Component\Config\Definition\BaseNode', $childChildren['foo']);
$this->assertSame('propagation/child/foo', $childChildren['foo']->getPath());
}
/**
* @group legacy
* @expectedDeprecation A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0.
*/
public function testInitializingTreeBuildersWithoutRootNode()
{
new TreeBuilder();
}
/**
* @group legacy
* @expectedDeprecation The "Symfony\Component\Config\Definition\Builder\TreeBuilder::root()" method called for the "foo" configuration is deprecated since Symfony 4.3, pass the root name to the constructor instead.
*/
public function testRoot()
{
$builder = new TreeBuilder('foo');
$builder->root('foo');
}
}

View File

@ -390,7 +390,7 @@ class EnvConfigurationWithoutRootNode implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
return new TreeBuilder();
return new TreeBuilder('env_extension');
}
}
@ -398,8 +398,8 @@ class ConfigurationWithArrayNodeRequiringOneElement implements ConfigurationInte
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$treeBuilder->root('env_extension')
$treeBuilder = new TreeBuilder('env_extension');
$treeBuilder
->children()
->arrayNode('nodes')
->isRequired()