composer package updates
[openemr.git] / vendor / symfony / config / Definition / VariableNode.php
blob0cd84c72bf303431690dab26a7d6055fae5b7343
1 <?php
3 /*
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;
16 /**
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;
30 public function setDefaultValue($value)
32 $this->defaultValueSet = true;
33 $this->defaultValue = $value;
36 /**
37 * {@inheritdoc}
39 public function hasDefaultValue()
41 return $this->defaultValueSet;
44 /**
45 * {@inheritdoc}
47 public function getDefaultValue()
49 $v = $this->defaultValue;
51 return $v instanceof \Closure ? $v() : $v;
54 /**
55 * Sets if this node is allowed to have an empty value.
57 * @param bool $boolean True if this entity will accept empty values
59 public function setAllowEmptyValue($boolean)
61 $this->allowEmptyValue = (bool) $boolean;
64 /**
65 * {@inheritdoc}
67 public function setName($name)
69 $this->name = $name;
72 /**
73 * {@inheritdoc}
75 protected function validateType($value)
79 /**
80 * {@inheritdoc}
82 protected function finalizeValue($value)
84 if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
85 $ex = new InvalidConfigurationException(sprintf(
86 'The path "%s" cannot contain an empty value, but got %s.',
87 $this->getPath(),
88 json_encode($value)
89 ));
90 if ($hint = $this->getInfo()) {
91 $ex->addHint($hint);
93 $ex->setPath($this->getPath());
95 throw $ex;
98 return $value;
102 * {@inheritdoc}
104 protected function normalizeValue($value)
106 return $value;
110 * {@inheritdoc}
112 protected function mergeValues($leftSide, $rightSide)
114 return $rightSide;
118 * Evaluates if the given value is to be treated as empty.
120 * By default, PHP's empty() function is used to test for emptiness. This
121 * method may be overridden by subtypes to better match their understanding
122 * of empty data.
124 * @param mixed $value
126 * @return bool
128 protected function isValueEmpty($value)
130 return empty($value);