Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Enum.php

class Enum

Same name in this branch
  1. 11.1.x vendor/google/protobuf/src/Google/Protobuf/Enum.php \Google\Protobuf\Enum

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

@Annotation

Plugin annotation


@Attributes({
   @Attribute("value",   required = true,  type = "array"),
   @Attribute("literal", required = false, type = "array")
})

Hierarchy

  • class \Doctrine\Common\Annotations\Annotation\Enum

Expanded class hierarchy of Enum

2 files declare their use of Enum
DocParser.php in vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php
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&gt;. It was copied from version 1.2.7.
11 string references to 'Enum'
Constraint::checkEnum in vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php
Checks a enum element
CoreExtension::getFunctions in vendor/twig/twig/src/Extension/CoreExtension.php
Returns a list of functions to add to the existing list.
EnumCasesFunction::compile in vendor/twig/twig/src/Node/Expression/FunctionNode/EnumCasesFunction.php
EnumConstraint::check in vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/EnumConstraint.php
invokes the validation of an element
EnumFunction::compile in vendor/twig/twig/src/Node/Expression/FunctionNode/EnumFunction.php

... See full list

File

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

Namespace

Doctrine\Common\Annotations\Annotation
View 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&lt;scalar&gt;
Enum::__construct public function @phpstan-param array{literal?: mixed[], value: list&lt;scalar&gt;} $values
RSS feed
Powered by Drupal