function DocParser::ArrayX

Same name in other branches
  1. 9 core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php \Drupal\Component\Annotation\Doctrine\DocParser::Arrayx()
  2. 8.9.x core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php \Drupal\Component\Annotation\Doctrine\DocParser::Arrayx()
  3. 11.x core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php \Drupal\Component\Annotation\Doctrine\DocParser::ArrayX()

Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}"

Return value

array

1 call to DocParser::ArrayX()
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 1097

Class

DocParser
A parser for docblock annotations.

Namespace

Drupal\Component\Annotation\Doctrine

Code

private function ArrayX() {
    $array = $values = array();
    $this->match(DocLexer::T_OPEN_CURLY_BRACES);
    // If the array is empty, stop parsing and return.
    if ($this->lexer
        ->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
        $this->match(DocLexer::T_CLOSE_CURLY_BRACES);
        return $array;
    }
    $values[] = $this->ArrayEntry();
    while ($this->lexer
        ->isNextToken(DocLexer::T_COMMA)) {
        $this->match(DocLexer::T_COMMA);
        // optional trailing comma
        if ($this->lexer
            ->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
            break;
        }
        $values[] = $this->ArrayEntry();
    }
    $this->match(DocLexer::T_CLOSE_CURLY_BRACES);
    foreach ($values as $value) {
        [
            $key,
            $val,
        ] = $value;
        if ($key !== null) {
            $array[$key] = $val;
        }
        else {
            $array[] = $val;
        }
    }
    return $array;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.