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

Breadcrumb

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

function Target::__construct

Same name in this branch
  1. 11.1.x vendor/symfony/dependency-injection/Attribute/Target.php \Symfony\Component\DependencyInjection\Attribute\Target::__construct()

@phpstan-param array{value?: string|list<string>} $values

Throws

InvalidArgumentException

File

vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php, line 63

Class

Target
Annotation that can be used to signal to the parser to check the annotation target during the parsing process.

Namespace

Doctrine\Common\Annotations\Annotation

Code

public function __construct(array $values) {
    if (!isset($values['value'])) {
        $values['value'] = null;
    }
    if (is_string($values['value'])) {
        $values['value'] = [
            $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);
}
RSS feed
Powered by Drupal