4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Config\Definition;
14 use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
17 * This node represents a value of variable type in the config tree.
19 * This node is intended for values of arbitrary type.
20 * Any PHP type is accepted as a value.
22 * @author Jeremy Mikola <jmikola@gmail.com>
24 class VariableNode extends BaseNode implements PrototypeNodeInterface
26 protected $defaultValueSet = false;
27 protected $defaultValue;
28 protected $allowEmptyValue = true;
33 public function setDefaultValue($value)
35 $this->defaultValueSet = true;
36 $this->defaultValue = $value;
42 public function hasDefaultValue()
44 return $this->defaultValueSet;
50 public function getDefaultValue()
52 $v = $this->defaultValue;
54 return $v instanceof \Closure ? $v() : $v;
58 * Sets if this node is allowed to have an empty value.
60 * @param bool $boolean True if this entity will accept empty values
62 public function setAllowEmptyValue($boolean)
64 $this->allowEmptyValue = (bool) $boolean;
70 public function setName($name)
78 protected function validateType($value)
85 protected function finalizeValue($value)
87 if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
88 $ex = new InvalidConfigurationException(sprintf(
89 'The path "%s" cannot contain an empty value, but got %s.',
93 if ($hint = $this->getInfo()) {
96 $ex->setPath($this->getPath());
107 protected function normalizeValue($value)
115 protected function mergeValues($leftSide, $rightSide)
121 * Evaluates if the given value is to be treated as empty.
123 * By default, PHP's empty() function is used to test for emptiness. This
124 * method may be overridden by subtypes to better match their understanding
127 * @param mixed $value
131 protected function isValueEmpty($value)
133 return empty($value);