[Config] replaced setInfo(), setExample() with more generic attributes
This commit is contained in:
parent
9e9519913d
commit
8775f2c17c
@ -56,7 +56,7 @@ class Configuration implements ConfigurationInterface
|
||||
->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 @@ class Configuration implements ConfigurationInterface
|
||||
->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 @@ class Configuration implements ConfigurationInterface
|
||||
$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 @@ class Configuration implements ConfigurationInterface
|
||||
|
||||
$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 @@ abstract class BaseNode implements NodeInterface
|
||||
$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 @@ abstract class BaseNode implements NodeInterface
|
||||
*/
|
||||
public function getInfo()
|
||||
{
|
||||
return $this->info;
|
||||
return $this->getAttribute('info');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +111,7 @@ abstract class BaseNode implements NodeInterface
|
||||
*/
|
||||
public function setExample($example)
|
||||
{
|
||||
$this->example = $example;
|
||||
$this->setAttribute('example', $example);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +121,7 @@ abstract class BaseNode implements NodeInterface
|
||||
*/
|
||||
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 @@ abstract class NodeDefinition implements NodeParentInterface
|
||||
*
|
||||
* @return NodeDefinition
|
||||
*/
|
||||
public function setInfo($info)
|
||||
public function info($info)
|
||||
{
|
||||
$this->info = $info;
|
||||
|
||||
return $this;
|
||||
return $this->attribute('info', $info);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,9 +83,22 @@ abstract class NodeDefinition implements NodeParentInterface
|
||||
*
|
||||
* @return NodeDefinition
|
||||
*/
|
||||
public function setExample($example)
|
||||
public function example($example)
|
||||
{
|
||||
$this->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->attributes[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -125,9 +135,7 @@ abstract class NodeDefinition implements NodeParentInterface
|
||||
}
|
||||
|
||||
$node = $this->createNode();
|
||||
|
||||
$node->setInfo($this->info);
|
||||
$node->setExample($this->example);
|
||||
$node->setAttributes($this->attributes);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
@ -94,9 +94,9 @@ class TreeBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$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 @@ class TreeBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$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();
|
||||
|
||||
|
Reference in New Issue
Block a user