You are here

public function Enum::__construct in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php \Doctrine\Common\Annotations\Annotation\Enum::__construct()

Annotation constructor.

Parameters

array $values:

Throws

\InvalidArgumentException

File

vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php, line 57

Class

Enum
Annotation that can be used to signal to the parser to check the available values during the parsing process.

Namespace

Doctrine\Common\Annotations\Annotation

Code

public function __construct(array $values) {
  if (!isset($values['literal'])) {
    $values['literal'] = array();
  }
  foreach ($values['value'] as $var) {
    if (!is_scalar($var)) {
      throw new \InvalidArgumentException(sprintf('@Enum supports only scalar values "%s" given.', is_object($var) ? get_class($var) : gettype($var)));
    }
  }
  foreach ($values['literal'] as $key => $var) {
    if (!in_array($key, $values['value'])) {
      throw new \InvalidArgumentException(sprintf('Undefined enumerator value "%s" for literal "%s".', $key, $var));
    }
  }
  $this->value = $values['value'];
  $this->literal = $values['literal'];
}