You are here

private function DocParser::collectAttributeTypeMetadata in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php \Drupal\Component\Annotation\Doctrine\DocParser::collectAttributeTypeMetadata()

Collects parsing metadata for a given attribute.

Parameters

array $metadata:

Attribute $attribute:

Return value

void

1 call to DocParser::collectAttributeTypeMetadata()
DocParser::collectAnnotationMetadata in core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php
Collects parsing metadata for a given annotation class

File

core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php, line 565
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.

Class

DocParser
A parser for docblock annotations.

Namespace

Drupal\Component\Annotation\Doctrine

Code

private function collectAttributeTypeMetadata(&$metadata, Attribute $attribute) {

  // handle internal type declaration
  $type = isset(self::$typeMap[$attribute->type]) ? self::$typeMap[$attribute->type] : $attribute->type;

  // handle the case if the property type is mixed
  if ('mixed' === $type) {
    return;
  }

  // Evaluate type
  switch (true) {

    // Checks if the property has array<type>
    case false !== ($pos = strpos($type, '<')):
      $arrayType = substr($type, $pos + 1, -1);
      $type = 'array';
      if (isset(self::$typeMap[$arrayType])) {
        $arrayType = self::$typeMap[$arrayType];
      }
      $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType;
      break;

    // Checks if the property has type[]
    case false !== ($pos = strrpos($type, '[')):
      $arrayType = substr($type, 0, $pos);
      $type = 'array';
      if (isset(self::$typeMap[$arrayType])) {
        $arrayType = self::$typeMap[$arrayType];
      }
      $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType;
      break;
  }
  $metadata['attribute_types'][$attribute->name]['type'] = $type;
  $metadata['attribute_types'][$attribute->name]['value'] = $attribute->type;
  $metadata['attribute_types'][$attribute->name]['required'] = $attribute->required;
}