Skip to content

Commit

Permalink
[DependencyInjection] Adding a NodeBuilder::addNodeBuilder() method t…
Browse files Browse the repository at this point in the history
…hat helps achieve a fluid interface when a pre-built NodeBuilder needs to be added.
  • Loading branch information
weaverryan committed Feb 18, 2011
1 parent f5b1cb1 commit bd15ddd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php
Expand Up @@ -101,6 +101,29 @@ public function node($name, $type)
return $this->children[$name] = $node;
}

/**
* Add a NodeBuilder instance directly.
*
* This helps achieve a fluid interface when a method on your Configuration
* class returns a pre-build NodeBuilder instance on your behalf:
*
* $root = new NodeBuilder();
* ->node('foo', 'scalar')
* ->addNodeBuilder($this->getBarNodeBuilder())
* ->node('baz', 'scalar')
* ;
*
* @return Symfony\Component\DependencyInjection\Configuration\Builder\NodeBuilder This builder node
*/
public function addNodeBuilder(NodeBuilder $node)
{
$node->parent = $this;

$this->children[$node->name] = $node;

return $this;
}

/**
* Creates a child array node
*
Expand Down
@@ -0,0 +1,18 @@
<?php

namespace Symfony\Tests\Component\DependencyInjection\Configuration;

use Symfony\Component\DependencyInjection\Configuration\Builder\NodeBuilder;

class NodeBuilderTest extends \PHPUnit_Framework_TestCase
{
public function testAddNodeBuilder()
{
$nodeBuilder = new NodeBuilder('root', array());
$childNode = new NodeBuilder('child', array());

$ret = $nodeBuilder->addNodeBuilder($childNode);
$this->assertEquals(array('child' => $childNode), $nodeBuilder->children);
$this->assertEquals($nodeBuilder, $ret);
}
}

0 comments on commit bd15ddd

Please sign in to comment.