diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index 1191a75218d7..873dc682569b 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -20,6 +20,7 @@ Config ------ * Deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()` + * Deprecated the `root()` method in `TreeBuilder`, pass the root node information to the constructor instead DependencyInjection ------------------- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index fbcc53cf4ac6..e90d60b60e3c 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -25,6 +25,7 @@ Config * The `Processor` class has been made final * Removed `FileLoaderLoadException`, use `LoaderLoadException` instead. * Using environment variables with `cannotBeEmpty()` if the value is validated with `validate()` will throw an exception. + * Removed the `root()` method in `TreeBuilder`, pass the root node information to the constructor instead Console ------- diff --git a/src/Symfony/Component/Config/CHANGELOG.md b/src/Symfony/Component/Config/CHANGELOG.md index 122184021c3b..4d15e9aedae8 100644 --- a/src/Symfony/Component/Config/CHANGELOG.md +++ b/src/Symfony/Component/Config/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()` * made `Resource\*` classes final and not implement `Serializable` anymore + * deprecated the `root()` method in `TreeBuilder`, pass the root node information to the constructor instead 4.2.0 ----- diff --git a/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php b/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php index 71e7976da7b8..9a3b0351d249 100644 --- a/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php @@ -29,7 +29,8 @@ public function __construct(string $name = null, string $type = 'array', NodeBui 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 { - $this->root($name, $type, $builder); + $builder = $builder ?: new NodeBuilder(); + $this->root = $builder->node($name, $type)->setParent($this); } } @@ -43,9 +44,13 @@ public function __construct(string $name = null, string $type = 'array', NodeBui * @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); diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php index 0dae83be41d9..d0e3d2d52d4b 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php @@ -197,4 +197,14 @@ 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'); + } }