Skip to content

Commit ce7d0c7

Browse files
committed
Deprecate TreeBuilder::root
1 parent 60be0fa commit ce7d0c7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()`
88
* made `Resource\*` classes final and not implement `Serializable` anymore
9+
* deprecated the `root()` method in `TreeBuilder`, pass the root node information to the constructor instead
910

1011
4.2.0
1112
-----

Definition/Builder/TreeBuilder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public function __construct(string $name = null, string $type = 'array', NodeBui
2929
if (null === $name) {
3030
@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);
3131
} else {
32-
$this->root($name, $type, $builder);
32+
$builder = $builder ?: new NodeBuilder();
33+
$this->root = $builder->node($name, $type)->setParent($this);
3334
}
3435
}
3536

@@ -43,9 +44,13 @@ public function __construct(string $name = null, string $type = 'array', NodeBui
4344
* @return ArrayNodeDefinition|NodeDefinition The root node (as an ArrayNodeDefinition when the type is 'array')
4445
*
4546
* @throws \RuntimeException When the node type is not supported
47+
*
48+
* @deprecated since Symfony 4.3, pass the root name to the constructor instead
4649
*/
4750
public function root($name, $type = 'array', NodeBuilder $builder = null)
4851
{
52+
@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);
53+
4954
$builder = $builder ?: new NodeBuilder();
5055

5156
return $this->root = $builder->node($name, $type)->setParent($this);

Tests/Definition/Builder/TreeBuilderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,14 @@ public function testInitializingTreeBuildersWithoutRootNode()
197197
{
198198
new TreeBuilder();
199199
}
200+
201+
/**
202+
* @group legacy
203+
* @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.
204+
*/
205+
public function testRoot()
206+
{
207+
$builder = new TreeBuilder('foo');
208+
$builder->root('foo');
209+
}
200210
}

0 commit comments

Comments
 (0)