Skip to content
Permalink
Browse files

[Config] replaced setInfo(), setExample() with more generic attributes

  • Loading branch information...
schmittjoh committed May 26, 2012
1 parent 9e95199 commit 8775f2c17ce8da1ae89269ddf2692a0c79ec7f3e
@@ -56,7 +56,7 @@ private function addFormSection(ArrayNodeDefinition $rootNode)
->arrayNode('resources')
->addDefaultChildrenIfNoneSet()
->prototype('scalar')->defaultValue('form_div_layout.html.twig')->end()
->setExample(array('MyBundle::form.html.twig'))
->example(array('MyBundle::form.html.twig'))
->validate()
->ifTrue(function($v) { return !in_array('form_div_layout.html.twig', $v); })
->then(function($v){
@@ -77,7 +77,7 @@ private function addGlobalsSection(ArrayNodeDefinition $rootNode)
->children()
->arrayNode('globals')
->useAttributeAsKey('key')
->setExample(array('foo' => '"@bar"', 'pi' => 3.14))
->example(array('foo' => '"@bar"', 'pi' => 3.14))
->prototype('array')
->beforeNormalization()
->ifTrue(function($v){ return is_string($v) && 0 === strpos($v, '@'); })
@@ -117,7 +117,7 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode)
$rootNode
->children()
->scalarNode('autoescape')->end()
->scalarNode('base_template_class')->setExample('Twig_Template')->end()
->scalarNode('base_template_class')->example('Twig_Template')->end()
->scalarNode('cache')->defaultValue('%kernel.cache_dir%/twig')->end()
->scalarNode('charset')->defaultValue('%kernel.charset%')->end()
->scalarNode('debug')->defaultValue('%kernel.debug%')->end()
@@ -36,7 +36,7 @@ public function getConfigTreeBuilder()
$rootNode
->children()
->booleanNode('verbose')->defaultTrue()->setInfo('DEPRECATED, it is not useful anymore and can be removed safely from your configuration')->end()
->booleanNode('verbose')->defaultTrue()->info('DEPRECATED, it is not useful anymore and can be removed safely from your configuration')->end()
->booleanNode('toolbar')->defaultFalse()->end()
->scalarNode('position')
->defaultValue('bottom')
@@ -29,8 +29,7 @@ abstract class BaseNode implements NodeInterface
protected $allowOverwrite;
protected $required;
protected $equivalentValues;
protected $info;
protected $example;
protected $attributes = array();
/**
* Constructor.
@@ -55,14 +54,44 @@ public function __construct($name, NodeInterface $parent = null)
$this->equivalentValues = array();
}
public function setAttribute($key, $value)
{
$this->attributes[$key] = $value;
}
public function getAttribute($key, $default = null)
{
return isset($this->attributes[$key]) ? $this->attributes[$key] : $default;
}
public function hasAttribute($key)
{
return isset($this->attributes[$key]);
}
public function getAttributes()
{
return $this->attributes;
}
public function setAttributes(array $attributes)
{
$this->attributes = $attributes;
}
public function removeAttribute($key)
{
unset($this->attributes[$key]);
}
/**
* Sets info message.
* Sets an info message.
*
* @param string $info The info text
* @param string $info
*/
public function setInfo($info)
{
$this->info = $info;
$this->setAttribute('info', $info);
}
/**
@@ -72,7 +101,7 @@ public function setInfo($info)
*/
public function getInfo()
{
return $this->info;
return $this->getAttribute('info');
}
/**
@@ -82,7 +111,7 @@ public function getInfo()
*/
public function setExample($example)
{
$this->example = $example;
$this->setAttribute('example', $example);
}
/**
@@ -92,7 +121,7 @@ public function setExample($example)
*/
public function getExample()
{
return $this->example;
return $this->getAttribute('example');
}
/**
@@ -32,8 +32,7 @@ abstract class NodeDefinition implements NodeParentInterface
protected $trueEquivalent;
protected $falseEquivalent;
protected $parent;
protected $info;
protected $example;
protected $attributes = array();
/**
* Constructor
@@ -72,11 +71,9 @@ public function setParent(NodeParentInterface $parent)
*
* @return NodeDefinition
*/
public function setInfo($info)
public function info($info)
{
$this->info = $info;
return $this;
return $this->attribute('info', $info);
}
/**
@@ -86,9 +83,22 @@ public function setInfo($info)
*
* @return NodeDefinition
*/
public function setExample($example)
public function example($example)
{
return $this->attribute('example', $example);
}
/**
* Sets an attribute on the node.
*
* @param string $key
* @param mixed $value
*
* @return NodeDefinition
*/
public function attribute($key, $value)
{
$this->example = $example;
$this->attributes[$key] = $value;
return $this;
}
@@ -125,9 +135,7 @@ public function getNode($forceRootNode = false)
}
$node = $this->createNode();
$node->setInfo($this->info);
$node->setExample($this->example);
$node->setAttributes($this->attributes);
return $node;
}
@@ -94,9 +94,9 @@ public function testDefinitionInfoGetsTransferedToNode()
{
$builder = new TreeBuilder();
$builder->root('test')->setInfo('root info')
$builder->root('test')->info('root info')
->children()
->node('child', 'variable')->setInfo('child info')->defaultValue('default')
->node('child', 'variable')->info('child info')->defaultValue('default')
->end()
->end();
@@ -112,9 +112,9 @@ public function testDefinitionExampleGetsTransferedToNode()
$builder = new TreeBuilder();
$builder->root('test')
->setExample(array('key' => 'value'))
->example(array('key' => 'value'))
->children()
->node('child', 'variable')->setInfo('child info')->defaultValue('default')->setExample('example')
->node('child', 'variable')->info('child info')->defaultValue('default')->example('example')
->end()
->end();

0 comments on commit 8775f2c

Please sign in to comment.
You can’t perform that action at this time.