class Enum
Annotation that can be used to signal to the parser to check the available values during the parsing process.
Plugin annotation
@Attributes({
@Attribute("value", required = true, type = "array"),
@Attribute("literal", required = false, type = "array")
})
Hierarchy
- class \Drupal\Component\Annotation\Doctrine\Annotation\Enum
Expanded class hierarchy of Enum
Related topics
1 file declares its use of Enum
- DocParser.php in core/
lib/ Drupal/ Component/ Annotation/ Doctrine/ DocParser.php - This class is a near-copy of Doctrine\Common\Annotations\DocParser, which is part of the Doctrine project: <http://www.doctrine-project.org>. It was copied from version 1.2.7.
File
-
core/
lib/ Drupal/ Component/ Annotation/ Doctrine/ Annotation/ Enum.php, line 47
Namespace
Drupal\Component\Annotation\Doctrine\AnnotationView source
final class Enum {
/** @phpstan-var list<scalar> */
public $value;
/**
* Literal target declaration.
*
* @var mixed[]
*/
public $literal;
/**
* @phpstan-param array{literal?: mixed[], value: list<scalar>} $values
*
* @throws InvalidArgumentException
*/
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'];
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| Enum::$literal | public | property | Literal target declaration. |
| Enum::$value | public | property | @phpstan-var list<scalar> |
| Enum::__construct | public | function | @phpstan-param array{literal?: mixed[], value: list<scalar>} $values |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.