1e0ed22c55
The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Component\Config\Definition\Builder;
|
|
|
|
use Symfony\Component\Config\Definition\NodeInterface;
|
|
use Symfony\Component\Config\Definition\VariableNode;
|
|
|
|
/**
|
|
* This class provides a fluent interface for defining a node.
|
|
*
|
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
*/
|
|
class VariableNodeDefinition extends NodeDefinition
|
|
{
|
|
/**
|
|
* Instantiate a Node
|
|
*
|
|
* @return VariableNode The node
|
|
*/
|
|
protected function instantiateNode()
|
|
{
|
|
return new VariableNode($this->name, $this->parent);
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
protected function createNode()
|
|
{
|
|
$node = $this->instantiateNode();
|
|
|
|
if (null !== $this->normalization) {
|
|
$node->setNormalizationClosures($this->normalization->before);
|
|
}
|
|
|
|
if (null !== $this->merge) {
|
|
$node->setAllowOverwrite($this->merge->allowOverwrite);
|
|
}
|
|
|
|
if (true === $this->default) {
|
|
$node->setDefaultValue($this->defaultValue);
|
|
}
|
|
|
|
if (false === $this->allowEmptyValue) {
|
|
$node->setAllowEmptyValue($this->allowEmptyValue);
|
|
}
|
|
|
|
$node->addEquivalentValue(null, $this->nullEquivalent);
|
|
$node->addEquivalentValue(true, $this->trueEquivalent);
|
|
$node->addEquivalentValue(false, $this->falseEquivalent);
|
|
$node->setRequired($this->required);
|
|
|
|
if (null !== $this->validation) {
|
|
$node->setFinalValidationClosures($this->validation->rules);
|
|
}
|
|
|
|
return $node;
|
|
}
|
|
|
|
} |