function Enum::__construct
@phpstan-param array{literal?: mixed[], value: list<scalar>} $values
Throws
InvalidArgumentException
File
-
core/
lib/ Drupal/ Component/ Annotation/ Doctrine/ Annotation/ Enum.php, line 64
Class
- Enum
- Annotation that can be used to signal to the parser to check the available values during the parsing process.
Namespace
Drupal\Component\Annotation\Doctrine\AnnotationCode
public function __construct(array $values) {
if (!isset($values['literal'])) {
$values['literal'] = [];
}
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'];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.