[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\Config\Definition; 13 14 use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; 15 16 /** 17 * This node represents a value of variable type in the config tree. 18 * 19 * This node is intended for values of arbitrary type. 20 * Any PHP type is accepted as a value. 21 * 22 * @author Jeremy Mikola <jmikola@gmail.com> 23 */ 24 class VariableNode extends BaseNode implements PrototypeNodeInterface 25 { 26 protected $defaultValueSet = false; 27 protected $defaultValue; 28 protected $allowEmptyValue = true; 29 30 /** 31 * {@inheritdoc} 32 */ 33 public function setDefaultValue($value) 34 { 35 $this->defaultValueSet = true; 36 $this->defaultValue = $value; 37 } 38 39 /** 40 * {@inheritdoc} 41 */ 42 public function hasDefaultValue() 43 { 44 return $this->defaultValueSet; 45 } 46 47 /** 48 * {@inheritdoc} 49 */ 50 public function getDefaultValue() 51 { 52 $v = $this->defaultValue; 53 54 return $v instanceof \Closure ? $v() : $v; 55 } 56 57 /** 58 * Sets if this node is allowed to have an empty value. 59 * 60 * @param bool $boolean True if this entity will accept empty values. 61 */ 62 public function setAllowEmptyValue($boolean) 63 { 64 $this->allowEmptyValue = (bool) $boolean; 65 } 66 67 /** 68 * {@inheritdoc} 69 */ 70 public function setName($name) 71 { 72 $this->name = $name; 73 } 74 75 /** 76 * {@inheritdoc} 77 */ 78 protected function validateType($value) 79 { 80 } 81 82 /** 83 * {@inheritdoc} 84 */ 85 protected function finalizeValue($value) 86 { 87 if (!$this->allowEmptyValue && $this->isValueEmpty($value)) { 88 $ex = new InvalidConfigurationException(sprintf( 89 'The path "%s" cannot contain an empty value, but got %s.', 90 $this->getPath(), 91 json_encode($value) 92 )); 93 $ex->setPath($this->getPath()); 94 95 throw $ex; 96 } 97 98 return $value; 99 } 100 101 /** 102 * {@inheritdoc} 103 */ 104 protected function normalizeValue($value) 105 { 106 return $value; 107 } 108 109 /** 110 * {@inheritdoc} 111 */ 112 protected function mergeValues($leftSide, $rightSide) 113 { 114 return $rightSide; 115 } 116 117 /** 118 * Evaluates if the given value is to be treated as empty. 119 * 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. 123 * 124 * @param mixed $value 125 * 126 * @return bool 127 */ 128 protected function isValueEmpty($value) 129 { 130 return empty($value); 131 } 132 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |