Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • ArrayNode
  • BaseNode
  • BooleanNode
  • EnumNode
  • FloatNode
  • IntegerNode
  • NumericNode
  • Processor
  • PrototypedArrayNode
  • ReferenceDumper
  • ScalarNode
  • VariableNode

Interfaces

  • ConfigurationInterface
  • NodeInterface
  • PrototypeNodeInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Symfony\Component\Config\Definition;
 4: 
 5: use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
 6: use Symfony\Component\Config\Definition\ScalarNode;
 7: 
 8: /**
 9:  * Node which only allows a finite set of values.
10:  *
11:  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
12:  */
13: class EnumNode extends ScalarNode
14: {
15:     private $values;
16: 
17:     public function __construct($name, NodeInterface $parent = null, array $values = array())
18:     {
19:         $values = array_unique($values);
20:         if (count($values) <= 1) {
21:             throw new \InvalidArgumentException('$values must contain at least two distinct elements.');
22:         }
23: 
24:         parent::__construct($name, $parent);
25:         $this->values = $values;
26:     }
27: 
28:     public function getValues()
29:     {
30:         return $this->values;
31:     }
32: 
33:     protected function finalizeValue($value)
34:     {
35:         $value = parent::finalizeValue($value);
36: 
37:         if (!in_array($value, $this->values, true)) {
38:             $ex = new InvalidConfigurationException(sprintf(
39:                 'The value %s is not allowed for path "%s". Permissible values: %s',
40:                 json_encode($value),
41:                 $this->getPath(),
42:                 implode(', ', array_map('json_encode', $this->values))));
43:             $ex->setPath($this->getPath());
44: 
45:             throw $ex;
46:         }
47: 
48:         return $value;
49:     }
50: }
51: 
php-coveralls API documentation generated by ApiGen 2.8.0