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

Breadcrumb

  1. Drupal Core 11.1.x

Enum.php

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

Namespace

Doctrine\Common\Annotations\Annotation

File

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

View source
<?php

namespace Doctrine\Common\Annotations\Annotation;

use InvalidArgumentException;
use function get_class;
use function gettype;
use function in_array;
use function is_object;
use function is_scalar;
use function sprintf;

/**
 * Annotation that can be used to signal to the parser
 * to check the available values during the parsing process.
 *
 * @Annotation
 * @Attributes({
 *    @Attribute("value",   required = true,  type = "array"),
 *    @Attribute("literal", required = false, type = "array")
 * })
 */
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'];
    }

}

Classes

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal