class Enum

Same name in this branch
  1. main core/lib/Drupal/Core/TypedData/Plugin/DataType/Enum.php \Drupal\Core\TypedData\Plugin\DataType\Enum
Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Component/Annotation/Doctrine/Annotation/Enum.php \Drupal\Component\Annotation\Doctrine\Annotation\Enum
  2. 11.x core/lib/Drupal/Core/TypedData/Plugin/DataType/Enum.php \Drupal\Core\TypedData\Plugin\DataType\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&gt;. It was copied from version 1.2.7.
5 string references to 'Enum'
config_enum_dependency_test.schema.yml in core/modules/config/tests/config_enum_dependency_test/config/schema/config_enum_dependency_test.schema.yml
core/modules/config/tests/config_enum_dependency_test/config/schema/config_enum_dependency_test.schema.yml
config_enum_test.schema.yml in core/modules/config/tests/config_enum_test/config/schema/config_enum_test.schema.yml
core/modules/config/tests/config_enum_test/config/schema/config_enum_test.schema.yml
core.data_types.schema.yml in core/config/schema/core.data_types.schema.yml
core/config/schema/core.data_types.schema.yml
Enum::getConstraints in core/lib/Drupal/Core/TypedData/Plugin/DataType/Enum.php
EnumConstraintValidatorTest::testValidation in core/tests/Drupal/KernelTests/Core/TypedData/EnumConstraintValidatorTest.php
Tests the constraint.

File

core/lib/Drupal/Component/Annotation/Doctrine/Annotation/Enum.php, line 47

Namespace

Drupal\Component\Annotation\Doctrine\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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.