You are here

private function DocParser::Constant in Drupal 10

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

Constant ::= integer | string | float | boolean

Return value

mixed

Throws

AnnotationException

2 calls to DocParser::Constant()
DocParser::ArrayEntry in core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php
ArrayEntry ::= Value | KeyValuePair KeyValuePair ::= Key ("=" | ":") PlainValue | Constant Key ::= string | integer | Constant
DocParser::PlainValue in core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php
PlainValue ::= integer | string | float | boolean | Array | Annotation

File

core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php, line 895
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 Constant() {
  $identifier = $this
    ->Identifier();
  if (!defined($identifier) && false !== strpos($identifier, '::') && '\\' !== $identifier[0]) {
    [
      $className,
      $const,
    ] = explode('::', $identifier);
    $alias = false === ($pos = strpos($className, '\\')) ? $className : substr($className, 0, $pos);
    $found = false;
    switch (true) {
      case !empty($this->namespaces):
        foreach ($this->namespaces as $ns) {
          if (class_exists($ns . '\\' . $className) || interface_exists($ns . '\\' . $className)) {
            $className = $ns . '\\' . $className;
            $found = true;
            break;
          }
        }
        break;
      case isset($this->imports[$loweredAlias = strtolower($alias)]):
        $found = true;
        $className = false !== $pos ? $this->imports[$loweredAlias] . substr($className, $pos) : $this->imports[$loweredAlias];
        break;
      default:
        if (isset($this->imports['__NAMESPACE__'])) {
          $ns = $this->imports['__NAMESPACE__'];
          if (class_exists($ns . '\\' . $className) || interface_exists($ns . '\\' . $className)) {
            $className = $ns . '\\' . $className;
            $found = true;
          }
        }
        break;
    }
    if ($found) {
      $identifier = $className . '::' . $const;
    }
  }

  // checks if identifier ends with ::class, \strlen('::class') === 7
  $classPos = stripos($identifier, '::class');
  if ($classPos === strlen($identifier) - 7) {
    return substr($identifier, 0, $classPos);
  }
  if (!defined($identifier)) {
    throw AnnotationException::semanticalErrorConstants($identifier, $this->context);
  }
  return constant($identifier);
}