You are here

final class Enum in Service Container 7.2

Same name and namespace in other branches
  1. 7 modules/providers/service_container_annotation_discovery/lib/Doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php \Doctrine\Common\Annotations\Annotation\Enum

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

@since 2.4 @author Fabio B. Silva <fabio.bat.silva@gmail.com>

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

1 file declares its use of Enum
DocParser.php in modules/providers/service_container_annotation_discovery/lib/Doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php

File

modules/providers/service_container_annotation_discovery/lib/Doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php, line 36

Namespace

Doctrine\Common\Annotations\Annotation
View source
final class Enum {

  /**
   * @var array
   */
  public $value;

  /**
   * Literal target declaration.
   *
   * @var array
   */
  public $literal;

  /**
   * Annotation constructor.
   *
   * @param array $values
   *
   * @throws \InvalidArgumentException
   */
  public function __construct(array $values) {
    if (!isset($values['literal'])) {
      $values['literal'] = array();
    }
    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

Namesort descending Modifiers Type Description Overrides
Enum::$literal public property Literal target declaration.
Enum::$value public property
Enum::__construct public function Annotation constructor.