Augmentation vers version 3.3.0
This commit is contained in:
@@ -25,7 +25,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
protected $performDeepMerging = true;
|
||||
protected $ignoreExtraKeys = false;
|
||||
protected $removeExtraKeys = true;
|
||||
protected $children = array();
|
||||
protected $children = [];
|
||||
protected $prototype;
|
||||
protected $atLeastOne = false;
|
||||
protected $allowNewKeys = true;
|
||||
@@ -43,8 +43,8 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
{
|
||||
parent::__construct($name, $parent);
|
||||
|
||||
$this->nullEquivalent = array();
|
||||
$this->trueEquivalent = array();
|
||||
$this->nullEquivalent = [];
|
||||
$this->trueEquivalent = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +75,62 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
return $this->prototype = $this->getNodeBuilder()->node(null, $type)->setParent($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return VariableNodeDefinition
|
||||
*/
|
||||
public function variablePrototype()
|
||||
{
|
||||
return $this->prototype('variable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ScalarNodeDefinition
|
||||
*/
|
||||
public function scalarPrototype()
|
||||
{
|
||||
return $this->prototype('scalar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BooleanNodeDefinition
|
||||
*/
|
||||
public function booleanPrototype()
|
||||
{
|
||||
return $this->prototype('boolean');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IntegerNodeDefinition
|
||||
*/
|
||||
public function integerPrototype()
|
||||
{
|
||||
return $this->prototype('integer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FloatNodeDefinition
|
||||
*/
|
||||
public function floatPrototype()
|
||||
{
|
||||
return $this->prototype('float');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayNodeDefinition
|
||||
*/
|
||||
public function arrayPrototype()
|
||||
{
|
||||
return $this->prototype('array');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EnumNodeDefinition
|
||||
*/
|
||||
public function enumPrototype()
|
||||
{
|
||||
return $this->prototype('enum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the default value if the node is not set in the configuration.
|
||||
*
|
||||
@@ -158,15 +214,15 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
* to be the key of the particular item. For example, if "id" is the
|
||||
* "key", then:
|
||||
*
|
||||
* array(
|
||||
* array('id' => 'my_name', 'foo' => 'bar'),
|
||||
* );
|
||||
* [
|
||||
* ['id' => 'my_name', 'foo' => 'bar'],
|
||||
* ];
|
||||
*
|
||||
* becomes
|
||||
*
|
||||
* array(
|
||||
* 'my_name' => array('foo' => 'bar'),
|
||||
* );
|
||||
* [
|
||||
* 'my_name' => ['foo' => 'bar'],
|
||||
* ];
|
||||
*
|
||||
* If you'd like "'id' => 'my_name'" to still be present in the resulting
|
||||
* array, then you can set the second argument of this method to false.
|
||||
@@ -219,9 +275,9 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
{
|
||||
$this
|
||||
->addDefaultsIfNotSet()
|
||||
->treatFalseLike(array('enabled' => false))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatFalseLike(['enabled' => false])
|
||||
->treatTrueLike(['enabled' => true])
|
||||
->treatNullLike(['enabled' => true])
|
||||
->beforeNormalization()
|
||||
->ifArray()
|
||||
->then(function ($v) {
|
||||
@@ -249,9 +305,9 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
{
|
||||
$this
|
||||
->addDefaultsIfNotSet()
|
||||
->treatFalseLike(array('enabled' => false))
|
||||
->treatTrueLike(array('enabled' => true))
|
||||
->treatNullLike(array('enabled' => true))
|
||||
->treatFalseLike(['enabled' => false])
|
||||
->treatTrueLike(['enabled' => true])
|
||||
->treatNullLike(['enabled' => true])
|
||||
->children()
|
||||
->booleanNode('enabled')
|
||||
->defaultTrue()
|
||||
@@ -276,10 +332,10 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
* Allows extra config keys to be specified under an array without
|
||||
* throwing an exception.
|
||||
*
|
||||
* Those config values are simply ignored and removed from the
|
||||
* resulting array. This should be used only in special cases where
|
||||
* you want to send an entire configuration array through a special
|
||||
* tree that processes only part of the array.
|
||||
* Those config values are ignored and removed from the resulting
|
||||
* array. This should be used only in special cases where you want
|
||||
* to send an entire configuration array through a special tree that
|
||||
* processes only part of the array.
|
||||
*
|
||||
* @param bool $remove Whether to remove the extra keys
|
||||
*
|
||||
@@ -356,6 +412,10 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
$node->setKeyAttribute($this->key, $this->removeKeyItem);
|
||||
}
|
||||
|
||||
if (false === $this->allowEmptyValue) {
|
||||
@trigger_error(sprintf('Using %s::cannotBeEmpty() at path "%s" has no effect, consider requiresAtLeastOneElement() instead. In 4.0 both methods will behave the same.', __CLASS__, $node->getPath()), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (true === $this->atLeastOne) {
|
||||
$node->setMinNumberOfElements(1);
|
||||
}
|
||||
@@ -381,6 +441,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
$node->addEquivalentValue(false, $this->falseEquivalent);
|
||||
$node->setPerformDeepMerging($this->performDeepMerging);
|
||||
$node->setRequired($this->required);
|
||||
$node->setDeprecated($this->deprecationMessage);
|
||||
$node->setIgnoreExtraKeys($this->ignoreExtraKeys, $this->removeExtraKeys);
|
||||
$node->setNormalizeKeys($this->normalizeKeys);
|
||||
|
||||
@@ -414,6 +475,10 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
throw new InvalidDefinitionException(sprintf('->useAttributeAsKey() is not applicable to concrete nodes at path "%s"', $path));
|
||||
}
|
||||
|
||||
if (false === $this->allowEmptyValue) {
|
||||
@trigger_error(sprintf('->cannotBeEmpty() is not applicable to concrete nodes at path "%s". In 4.0 it will throw an exception.', $path), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (true === $this->atLeastOne) {
|
||||
throw new InvalidDefinitionException(sprintf('->requiresAtLeastOneElement() is not applicable to concrete nodes at path "%s"', $path));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Config\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\BooleanNode;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
||||
|
||||
/**
|
||||
* This class provides a fluent interface for defining a node.
|
||||
@@ -30,18 +31,6 @@ class BooleanNodeDefinition extends ScalarNodeDefinition
|
||||
$this->nullEquivalent = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Deprecated since version 2.8, to be removed in 3.0.
|
||||
*/
|
||||
public function cannotBeEmpty()
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
return parent::cannotBeEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a Node.
|
||||
*
|
||||
@@ -51,4 +40,14 @@ class BooleanNodeDefinition extends ScalarNodeDefinition
|
||||
{
|
||||
return new BooleanNode($this->name, $this->parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidDefinitionException
|
||||
*/
|
||||
public function cannotBeEmpty()
|
||||
{
|
||||
throw new InvalidDefinitionException('->cannotBeEmpty() is not applicable to BooleanNodeDefinition.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,18 @@ class ExprBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the value is empty.
|
||||
*
|
||||
* @return ExprBuilder
|
||||
*/
|
||||
public function ifEmpty()
|
||||
{
|
||||
$this->ifPart = function ($v) { return empty($v); };
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the value is an array.
|
||||
*
|
||||
@@ -124,6 +136,19 @@ class ExprBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms variables of any type into an array.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function castToArray()
|
||||
{
|
||||
$this->ifPart = function ($v) { return !\is_array($v); };
|
||||
$this->thenPart = function ($v) { return [$v]; };
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the closure to run if the test pass.
|
||||
*
|
||||
@@ -143,7 +168,7 @@ class ExprBuilder
|
||||
*/
|
||||
public function thenEmptyArray()
|
||||
{
|
||||
$this->thenPart = function ($v) { return array(); };
|
||||
$this->thenPart = function ($v) { return []; };
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class NodeBuilder implements NodeParentInterface
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->nodeMapping = array(
|
||||
$this->nodeMapping = [
|
||||
'variable' => __NAMESPACE__.'\\VariableNodeDefinition',
|
||||
'scalar' => __NAMESPACE__.'\\ScalarNodeDefinition',
|
||||
'boolean' => __NAMESPACE__.'\\BooleanNodeDefinition',
|
||||
@@ -31,7 +31,7 @@ class NodeBuilder implements NodeParentInterface
|
||||
'float' => __NAMESPACE__.'\\FloatNodeDefinition',
|
||||
'array' => __NAMESPACE__.'\\ArrayNodeDefinition',
|
||||
'enum' => __NAMESPACE__.'\\EnumNodeDefinition',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,13 +27,14 @@ abstract class NodeDefinition implements NodeParentInterface
|
||||
protected $defaultValue;
|
||||
protected $default = false;
|
||||
protected $required = false;
|
||||
protected $deprecationMessage = null;
|
||||
protected $merge;
|
||||
protected $allowEmptyValue = true;
|
||||
protected $nullEquivalent;
|
||||
protected $trueEquivalent = true;
|
||||
protected $falseEquivalent = false;
|
||||
protected $parent;
|
||||
protected $attributes = array();
|
||||
protected $attributes = [];
|
||||
|
||||
/**
|
||||
* @param string|null $name The name of the node
|
||||
@@ -160,6 +161,23 @@ abstract class NodeDefinition implements NodeParentInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the node as deprecated.
|
||||
*
|
||||
* You can use %node% and %path% placeholders in your message to display,
|
||||
* respectively, the node name and its complete path.
|
||||
*
|
||||
* @param string $message Deprecation message
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeprecated($message = 'The child node "%node%" at path "%path%" is deprecated.')
|
||||
{
|
||||
$this->deprecationMessage = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the equivalent value used when the node contains null.
|
||||
*
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace Symfony\Component\Config\Definition\Builder;
|
||||
class NormalizationBuilder
|
||||
{
|
||||
protected $node;
|
||||
public $before = array();
|
||||
public $remappings = array();
|
||||
public $before = [];
|
||||
public $remappings = [];
|
||||
|
||||
public function __construct(NodeDefinition $node)
|
||||
{
|
||||
@@ -37,7 +37,7 @@ class NormalizationBuilder
|
||||
*/
|
||||
public function remap($key, $plural = null)
|
||||
{
|
||||
$this->remappings[] = array($key, null === $plural ? $key.'s' : $plural);
|
||||
$this->remappings[] = [$key, null === $plural ? $key.'s' : $plural];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Config\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
||||
|
||||
/**
|
||||
* Abstract class that contains common code of integer and float node definitions.
|
||||
*
|
||||
@@ -62,12 +64,10 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Deprecated since version 2.8, to be removed in 3.0.
|
||||
* @throws InvalidDefinitionException
|
||||
*/
|
||||
public function cannotBeEmpty()
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
return parent::cannotBeEmpty();
|
||||
throw new InvalidDefinitionException('->cannotBeEmpty() is not applicable to NumericNodeDefinition.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ class TreeBuilder implements NodeParentInterface
|
||||
{
|
||||
protected $tree;
|
||||
protected $root;
|
||||
|
||||
/**
|
||||
* @deprecated since 3.4. To be removed in 4.0
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Symfony\Component\Config\Definition\Builder;
|
||||
class ValidationBuilder
|
||||
{
|
||||
protected $node;
|
||||
public $rules = array();
|
||||
public $rules = [];
|
||||
|
||||
public function __construct(NodeDefinition $node)
|
||||
{
|
||||
|
||||
@@ -54,6 +54,7 @@ class VariableNodeDefinition extends NodeDefinition
|
||||
$node->addEquivalentValue(true, $this->trueEquivalent);
|
||||
$node->addEquivalentValue(false, $this->falseEquivalent);
|
||||
$node->setRequired($this->required);
|
||||
$node->setDeprecated($this->deprecationMessage);
|
||||
|
||||
if (null !== $this->validation) {
|
||||
$node->setFinalValidationClosures($this->validation->rules);
|
||||
|
||||
Reference in New Issue
Block a user