Skip to content

[Config] Deprecate TreeBuilder::root #31027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-4.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Config/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}