[ Index ] |
PHP Cross Reference of phpBB-3.2.11-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 * Node which only allows a finite set of values. 18 * 19 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 20 */ 21 class EnumNode extends ScalarNode 22 { 23 private $values; 24 25 public function __construct($name, NodeInterface $parent = null, array $values = array()) 26 { 27 $values = array_unique($values); 28 if (empty($values)) { 29 throw new \InvalidArgumentException('$values must contain at least one element.'); 30 } 31 32 parent::__construct($name, $parent); 33 $this->values = $values; 34 } 35 36 public function getValues() 37 { 38 return $this->values; 39 } 40 41 protected function finalizeValue($value) 42 { 43 $value = parent::finalizeValue($value); 44 45 if (!\in_array($value, $this->values, true)) { 46 $ex = new InvalidConfigurationException(sprintf('The value %s is not allowed for path "%s". Permissible values: %s', json_encode($value), $this->getPath(), implode(', ', array_map('json_encode', $this->values)))); 47 $ex->setPath($this->getPath()); 48 49 throw $ex; 50 } 51 52 return $value; 53 } 54 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |