[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/config/Symfony/Component/Config/Definition/Builder/ -> EnumNodeDefinition.php (source)

   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\Builder;
  13  
  14  use Symfony\Component\Config\Definition\EnumNode;
  15  
  16  /**
  17   * Enum Node Definition.
  18   *
  19   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  20   */
  21  class EnumNodeDefinition extends ScalarNodeDefinition
  22  {
  23      private $values;
  24  
  25      /**
  26       * @param array $values
  27       *
  28       * @return EnumNodeDefinition|$this
  29       */
  30      public function values(array $values)
  31      {
  32          $values = array_unique($values);
  33  
  34          if (count($values) <= 1) {
  35              throw new \InvalidArgumentException('->values() must be called with at least two distinct values.');
  36          }
  37  
  38          $this->values = $values;
  39  
  40          return $this;
  41      }
  42  
  43      /**
  44       * Instantiate a Node.
  45       *
  46       * @return EnumNode The node
  47       *
  48       * @throws \RuntimeException
  49       */
  50      protected function instantiateNode()
  51      {
  52          if (null === $this->values) {
  53              throw new \RuntimeException('You must call ->values() on enum nodes.');
  54          }
  55  
  56          return new EnumNode($this->name, $this->parent, $this->values);
  57      }
  58  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1