Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
VariableNode.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Config\Definition;
013
014 use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
015
016 /**
017 * This node represents a value of variable type in the config tree.
018 *
019 * This node is intended for values of arbitrary type.
020 * Any PHP type is accepted as a value.
021 *
022 * @author Jeremy Mikola <jmikola@gmail.com>
023 */
024 class VariableNode extends BaseNode implements PrototypeNodeInterface
025 {
026 protected $defaultValueSet = false;
027 protected $defaultValue;
028 protected $allowEmptyValue = true;
029
030 /**
031 * {@inheritdoc}
032 */
033 public function setDefaultValue($value)
034 {
035 $this->defaultValueSet = true;
036 $this->defaultValue = $value;
037 }
038
039 /**
040 * {@inheritdoc}
041 */
042 public function hasDefaultValue()
043 {
044 return $this->defaultValueSet;
045 }
046
047 /**
048 * {@inheritdoc}
049 */
050 public function getDefaultValue()
051 {
052 $v = $this->defaultValue;
053
054 return $v instanceof \Closure ? $v() : $v;
055 }
056
057 /**
058 * Sets if this node is allowed to have an empty value.
059 *
060 * @param bool $boolean True if this entity will accept empty values
061 */
062 public function setAllowEmptyValue($boolean)
063 {
064 $this->allowEmptyValue = (bool) $boolean;
065 }
066
067 /**
068 * {@inheritdoc}
069 */
070 public function setName($name)
071 {
072 $this->name = $name;
073 }
074
075 /**
076 * {@inheritdoc}
077 */
078 protected function validateType($value)
079 {
080 }
081
082 /**
083 * {@inheritdoc}
084 */
085 protected function finalizeValue($value)
086 {
087 if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
088 $ex = new InvalidConfigurationException(sprintf(
089 'The path "%s" cannot contain an empty value, but got %s.',
090 $this->getPath(),
091 json_encode($value)
092 ));
093 if ($hint = $this->getInfo()) {
094 $ex->addHint($hint);
095 }
096 $ex->setPath($this->getPath());
097
098 throw $ex;
099 }
100
101 return $value;
102 }
103
104 /**
105 * {@inheritdoc}
106 */
107 protected function normalizeValue($value)
108 {
109 return $value;
110 }
111
112 /**
113 * {@inheritdoc}
114 */
115 protected function mergeValues($leftSide, $rightSide)
116 {
117 return $rightSide;
118 }
119
120 /**
121 * Evaluates if the given value is to be treated as empty.
122 *
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
125 * of empty data.
126 *
127 * @param mixed $value
128 *
129 * @return bool
130 */
131 protected function isValueEmpty($value)
132 {
133 return empty($value);
134 }
135 }
136