merged branch schmittjoh/configAttr (PR #4425)
Commits -------23bb668
[FrameworkBundle][SecurityBundle] updated configuration to new method names8775f2c
[Config] replaced setInfo(), setExample() with more generic attributes Discussion ---------- [Config] replaced setInfo(), setExample() with more generic attributes This replaces ``setInfo`` and ``setExample`` with a more generic attribute system which provides more flexibility and is more future prove. I have kept the specialized ``setInfo`` and ``setExample`` methods because they are a bit shorter, and also a good demonstration of what the system could be used for. However for consistency, I have renamed them to ``info()`` and ``example()`` respectively. --------------------------------------------------------------------------- by travisbot at 2012-05-26T17:37:06Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1442720) (merged8775f2c1
into9e951991
). --------------------------------------------------------------------------- by stof at 2012-05-26T17:42:02Z and you forgot to update FrameworkBundle --------------------------------------------------------------------------- by travisbot at 2012-05-26T17:46:37Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1442764) (merged23bb668e
into9e951991
).
This commit is contained in:
commit
f5dee51c9e
@ -46,7 +46,7 @@ class Configuration implements ConfigurationInterface
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->scalarNode('charset')->setInfo('general configuration')->end()
|
||||
->scalarNode('charset')->info('general configuration')->end()
|
||||
->scalarNode('trust_proxy_headers')->defaultFalse()->end()
|
||||
->scalarNode('secret')->isRequired()->end()
|
||||
->scalarNode('ide')->defaultNull()->end()
|
||||
@ -73,7 +73,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('form')
|
||||
->setInfo('form configuration')
|
||||
->info('form configuration')
|
||||
->canBeUnset()
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
@ -99,7 +99,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('esi')
|
||||
->setInfo('esi configuration')
|
||||
->info('esi configuration')
|
||||
->canBeUnset()
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
@ -116,7 +116,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('profiler')
|
||||
->setInfo('profiler configuration')
|
||||
->info('profiler configuration')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->booleanNode('only_exceptions')->defaultFalse()->end()
|
||||
@ -131,8 +131,8 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->scalarNode('ip')->end()
|
||||
->scalarNode('path')
|
||||
->setInfo('use the urldecoded format')
|
||||
->setExample('^/path to resource/')
|
||||
->info('use the urldecoded format')
|
||||
->example('^/path to resource/')
|
||||
->end()
|
||||
->scalarNode('service')->end()
|
||||
->end()
|
||||
@ -148,7 +148,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('router')
|
||||
->setInfo('router configuration')
|
||||
->info('router configuration')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->scalarNode('resource')->isRequired()->end()
|
||||
@ -166,7 +166,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('session')
|
||||
->setInfo('session configuration')
|
||||
->info('session configuration')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->booleanNode('auto_start')->defaultFalse()->end()
|
||||
@ -182,11 +182,11 @@ class Configuration implements ConfigurationInterface
|
||||
->scalarNode('gc_probability')->end()
|
||||
->scalarNode('gc_maxlifetime')->end()
|
||||
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
|
||||
->scalarNode('lifetime')->setInfo('DEPRECATED! Please use: cookie_lifetime')->end()
|
||||
->scalarNode('path')->setInfo('DEPRECATED! Please use: cookie_path')->end()
|
||||
->scalarNode('domain')->setInfo('DEPRECATED! Please use: cookie_domain')->end()
|
||||
->booleanNode('secure')->setInfo('DEPRECATED! Please use: cookie_secure')->end()
|
||||
->booleanNode('httponly')->setInfo('DEPRECATED! Please use: cookie_httponly')->end()
|
||||
->scalarNode('lifetime')->info('DEPRECATED! Please use: cookie_lifetime')->end()
|
||||
->scalarNode('path')->info('DEPRECATED! Please use: cookie_path')->end()
|
||||
->scalarNode('domain')->info('DEPRECATED! Please use: cookie_domain')->end()
|
||||
->booleanNode('secure')->info('DEPRECATED! Please use: cookie_secure')->end()
|
||||
->booleanNode('httponly')->info('DEPRECATED! Please use: cookie_httponly')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
@ -218,7 +218,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('templating')
|
||||
->setInfo('templating configuration')
|
||||
->info('templating configuration')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->scalarNode('assets_version')->defaultValue(null)->end()
|
||||
@ -268,7 +268,7 @@ class Configuration implements ConfigurationInterface
|
||||
->fixXmlConfig('engine')
|
||||
->children()
|
||||
->arrayNode('engines')
|
||||
->setExample(array('twig'))
|
||||
->example(array('twig'))
|
||||
->isRequired()
|
||||
->requiresAtLeastOneElement()
|
||||
->beforeNormalization()
|
||||
@ -331,7 +331,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('translator')
|
||||
->setInfo('translator configuration')
|
||||
->info('translator configuration')
|
||||
->canBeUnset()
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
@ -349,7 +349,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('validation')
|
||||
->setInfo('validation configuration')
|
||||
->info('validation configuration')
|
||||
->canBeUnset()
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
@ -368,7 +368,7 @@ class Configuration implements ConfigurationInterface
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('annotations')
|
||||
->setInfo('annotation configuration')
|
||||
->info('annotation configuration')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('cache')->defaultValue('file')->end()
|
||||
|
@ -57,8 +57,8 @@ class MainConfiguration implements ConfigurationInterface
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->scalarNode('access_denied_url')->defaultNull()->setExample('/foo/error403')->end()
|
||||
->scalarNode('session_fixation_strategy')->cannotBeEmpty()->setInfo('strategy can be: none, migrate, invalidate')->defaultValue('migrate')->end()
|
||||
->scalarNode('access_denied_url')->defaultNull()->example('/foo/error403')->end()
|
||||
->scalarNode('session_fixation_strategy')->cannotBeEmpty()->info('strategy can be: none, migrate, invalidate')->defaultValue('migrate')->end()
|
||||
->booleanNode('hide_user_not_found')->defaultTrue()->end()
|
||||
->booleanNode('always_authenticate_before_granting')->defaultFalse()->end()
|
||||
->booleanNode('erase_credentials')->defaultTrue()->end()
|
||||
@ -91,7 +91,7 @@ class MainConfiguration implements ConfigurationInterface
|
||||
->children()
|
||||
->scalarNode('connection')
|
||||
->defaultNull()
|
||||
->setInfo('any name configured in doctrine.dbal section')
|
||||
->info('any name configured in doctrine.dbal section')
|
||||
->end()
|
||||
->arrayNode('cache')
|
||||
->addDefaultsIfNotSet()
|
||||
@ -156,8 +156,8 @@ class MainConfiguration implements ConfigurationInterface
|
||||
->scalarNode('requires_channel')->defaultNull()->end()
|
||||
->scalarNode('path')
|
||||
->defaultNull()
|
||||
->setInfo('use the urldecoded format')
|
||||
->setExample('^/path to resource/')
|
||||
->info('use the urldecoded format')
|
||||
->example('^/path to resource/')
|
||||
->end()
|
||||
->scalarNode('host')->defaultNull()->end()
|
||||
->scalarNode('ip')->defaultNull()->end()
|
||||
@ -300,7 +300,7 @@ class MainConfiguration implements ConfigurationInterface
|
||||
->fixXmlConfig('provider')
|
||||
->children()
|
||||
->arrayNode('providers')
|
||||
->setExample(array(
|
||||
->example(array(
|
||||
'memory' => array(
|
||||
'name' => 'memory',
|
||||
'users' => array(
|
||||
@ -360,7 +360,7 @@ class MainConfiguration implements ConfigurationInterface
|
||||
->fixXmlConfig('encoder')
|
||||
->children()
|
||||
->arrayNode('encoders')
|
||||
->setExample(array(
|
||||
->example(array(
|
||||
'Acme\DemoBundle\Entity\User1' => 'sha512',
|
||||
'Acme\DemoBundle\Entity\User2' => array(
|
||||
'algorithm' => 'sha512',
|
||||
|
@ -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