123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace Doctrine\Common\Annotations\Annotation;
- final class Target
- {
- const TARGET_CLASS = 1;
- const TARGET_METHOD = 2;
- const TARGET_PROPERTY = 4;
- const TARGET_ANNOTATION = 8;
- const TARGET_ALL = 15;
-
- private static $map = array(
- 'ALL' => self::TARGET_ALL,
- 'CLASS' => self::TARGET_CLASS,
- 'METHOD' => self::TARGET_METHOD,
- 'PROPERTY' => self::TARGET_PROPERTY,
- 'ANNOTATION' => self::TARGET_ANNOTATION,
- );
-
- public $value;
-
- public $targets;
-
- public $literal;
-
- public function __construct(array $values)
- {
- if (!isset($values['value'])){
- $values['value'] = null;
- }
- if (is_string($values['value'])){
- $values['value'] = array($values['value']);
- }
- if (!is_array($values['value'])){
- throw new \InvalidArgumentException(
- sprintf('@Target expects either a string value, or an array of strings, "%s" given.',
- is_object($values['value']) ? get_class($values['value']) : gettype($values['value'])
- )
- );
- }
- $bitmask = 0;
- foreach ($values['value'] as $literal) {
- if(!isset(self::$map[$literal])){
- throw new \InvalidArgumentException(
- sprintf('Invalid Target "%s". Available targets: [%s]',
- $literal, implode(', ', array_keys(self::$map)))
- );
- }
- $bitmask += self::$map[$literal];
- }
- $this->targets = $bitmask;
- $this->value = $values['value'];
- $this->literal = implode(', ', $this->value);
- }
- }
|