Skip to content

Commit

Permalink
minor #31932 [Config] remove the root method and the nullable name (S…
Browse files Browse the repository at this point in the history
…imperfit)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Config] remove the root method and the nullable name

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | none   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | none <!-- required for new features -->

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

This PR allows to remove the both deprecated path of the `TreeBuilder` and update tests accordingly.

Commits
-------

7c66e6f [Config] remove the root method and the nullable name
  • Loading branch information
nicolas-grekas committed Jun 7, 2019
2 parents 1af3952 + 7c66e6f commit 0fb9b1b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 50 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Config/CHANGELOG.md
@@ -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
-----

Expand Down
30 changes: 2 additions & 28 deletions src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php
Expand Up @@ -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);
}

/**
Expand Down
Expand Up @@ -188,23 +188,4 @@ public function testPathSeparatorIsPropagatedToChildren()
$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');
}
}
Expand Up @@ -390,16 +390,16 @@ class EnvConfigurationWithoutRootNode implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
return new TreeBuilder();
return new TreeBuilder('env_extension');
}
}

class ConfigurationWithArrayNodeRequiringOneElement implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$treeBuilder->root('env_extension')
$treeBuilder = new TreeBuilder('env_extension');
$treeBuilder
->children()
->arrayNode('nodes')
->isRequired()
Expand Down

0 comments on commit 0fb9b1b

Please sign in to comment.