. */ namespace Doctrine\Common\Annotations\Annotation; /** * Annotation that can be used to signal to the parser * to check the available values during the parsing process. * * @since 2.4 * @author Fabio B. Silva * * @Annotation * @Attributes({ * @Attribute("value", required = true, type = "array"), * @Attribute("literal", required = false, type = "array") * }) */ final class Enum { /** * @var array */ public $value; /** * Literal target declaration. * * @var array */ public $literal; /** * Annotation construct * * @param array $values * * @throws \InvalidArgumentException */ 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']; } }