4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Config\Definition\Builder;
14 use Symfony\Component\Config\Definition\NodeInterface;
17 * This is the entry class for building a config tree.
19 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
21 class TreeBuilder implements NodeParentInterface
28 * Creates the root node.
30 * @param string $name The name of the root node
31 * @param string $type The type of the root node
32 * @param NodeBuilder $builder A custom node builder instance
34 * @return ArrayNodeDefinition|NodeDefinition The root node (as an ArrayNodeDefinition when the type is 'array')
36 * @throws \RuntimeException When the node type is not supported
38 public function root($name, $type = 'array', NodeBuilder $builder = null)
40 $builder = $builder ?: new NodeBuilder();
42 return $this->root = $builder->node($name, $type)->setParent($this);
48 * @return NodeInterface
50 * @throws \RuntimeException
52 public function buildTree()
54 if (null === $this->root) {
55 throw new \RuntimeException('The configuration tree has no root node.');
57 if (null !== $this->tree) {
61 return $this->tree = $this->root->getNode(true);