class Target
Annotation that can be used to signal to the parser to check the annotation target during the parsing process.
Hierarchy
- class \Drupal\Component\Annotation\Doctrine\Annotation\Target
Expanded class hierarchy of Target
Related topics
2 files declare their use of Target
- 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>. It was copied from version 1.2.7.
- DocParserTest.php in core/tests/ Drupal/ Tests/ Component/ Annotation/ Doctrine/ DocParserTest.php 
10 string references to 'Target'
- ContentTranslationController::overview in core/modules/ content_translation/ src/ Controller/ ContentTranslationController.php 
- Builds the translations overview page.
- FieldPluginBase::buildOptionsForm in core/modules/ views/ src/ Plugin/ views/ field/ FieldPluginBase.php 
- Default option form that provides label widget that all fields should have.
- HtmxAttributesTest::hxSimpleStringAttributesDataProvider in core/tests/ Drupal/ Tests/ Core/ Htmx/ HtmxAttributesTest.php 
- Provides data to ::testHxSimpleStringAttributes.
- LinkFormatter::settingsForm in core/modules/ link/ src/ Plugin/ Field/ FieldFormatter/ LinkFormatter.php 
- Returns a form to configure settings for the formatter.
- MachineName::processMachineName in core/lib/ Drupal/ Core/ Render/ Element/ MachineName.php 
- Processes a machine-readable name form element.
16 classes are annotated with Target
- AnnotationEnum in core/tests/ Drupal/ Tests/ Component/ Annotation/ Doctrine/ Fixtures/ AnnotationEnum.php 
- Plugin annotation @Target("ALL");
- AnnotationEnumInvalid in core/tests/ Drupal/ Tests/ Component/ Annotation/ Doctrine/ Fixtures/ AnnotationEnumInvalid.php 
- Plugin annotation @Target("ALL");
- AnnotationEnumLiteral in core/tests/ Drupal/ Tests/ Component/ Annotation/ Doctrine/ Fixtures/ AnnotationEnumLiteral.php 
- Plugin annotation @Target("ALL");
- AnnotationEnumLiteralInvalid in core/tests/ Drupal/ Tests/ Component/ Annotation/ Doctrine/ Fixtures/ AnnotationEnumLiteralInvalid.php 
- Plugin annotation @Target("ALL");
- AnnotationTargetAll in core/tests/ Drupal/ Tests/ Component/ Annotation/ Doctrine/ Fixtures/ AnnotationTargetAll.php 
- Plugin annotation @Target("ALL");
File
- 
              core/lib/ Drupal/ Component/ Annotation/ Doctrine/ Annotation/ Target.php, line 45 
Namespace
Drupal\Component\Annotation\Doctrine\AnnotationView source
final class Target {
  public const TARGET_CLASS = 1;
  public const TARGET_METHOD = 2;
  public const TARGET_PROPERTY = 4;
  public const TARGET_ANNOTATION = 8;
  public const TARGET_FUNCTION = 16;
  public const TARGET_ALL = 31;
  /** @var array<string, int> */
  private static $map = [
    'ALL' => self::TARGET_ALL,
    'CLASS' => self::TARGET_CLASS,
    'METHOD' => self::TARGET_METHOD,
    'PROPERTY' => self::TARGET_PROPERTY,
    'FUNCTION' => self::TARGET_FUNCTION,
    'ANNOTATION' => self::TARGET_ANNOTATION,
  ];
  /** @phpstan-var list<string> */
  public $value;
  
  /**
   * Targets as bitmask.
   *
   * @var int
   */
  public $targets;
  
  /**
   * Literal target declaration.
   *
   * @var string
   */
  public $literal;
  
  /**
   * @phpstan-param array{value?: string|list<string>} $values
   *
   * @throws InvalidArgumentException
   */
  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);
  }
}Members
| Title Sort descending | Modifiers | Object type | Summary | 
|---|---|---|---|
| Target::$literal | public | property | Literal target declaration. | 
| Target::$map | private static | property | @var array<string, int> | 
| Target::$targets | public | property | Targets as bitmask. | 
| Target::$value | public | property | @phpstan-var list<string> | 
| Target::TARGET_ALL | public | constant | |
| Target::TARGET_ANNOTATION | public | constant | |
| Target::TARGET_CLASS | public | constant | |
| Target::TARGET_FUNCTION | public | constant | |
| Target::TARGET_METHOD | public | constant | |
| Target::TARGET_PROPERTY | public | constant | |
| Target::__construct | public | function | @phpstan-param array{value?: string|list<string>} $values | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
