8000 Deprecate TreeBuilder::root · symfony/symfony@0d4689b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d4689b

Browse files
committed
Deprecate TreeBuilder::root
1 parent 6a5de47 commit 0d4689b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Component/Config/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);

src/Symfony/Component/Config/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)
0