You are here

public function TokenParser::parseUseStatement in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php \Doctrine\Common\Annotations\TokenParser::parseUseStatement()

Parses a single use statement.

Return value

array A list with all found class names for a use statement.

1 call to TokenParser::parseUseStatement()
TokenParser::parseUseStatements in vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php
Gets all use statements.

File

vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php, line 100

Class

TokenParser
Parses a file for namespaces/use/class declarations.

Namespace

Doctrine\Common\Annotations

Code

public function parseUseStatement() {
  $class = '';
  $alias = '';
  $statements = array();
  $explicitAlias = false;
  while ($token = $this
    ->next()) {
    $isNameToken = $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR;
    if (!$explicitAlias && $isNameToken) {
      $class .= $token[1];
      $alias = $token[1];
    }
    else {
      if ($explicitAlias && $isNameToken) {
        $alias .= $token[1];
      }
      else {
        if ($token[0] === T_AS) {
          $explicitAlias = true;
          $alias = '';
        }
        else {
          if ($token === ',') {
            $statements[strtolower($alias)] = $class;
            $class = '';
            $alias = '';
            $explicitAlias = false;
          }
          else {
            if ($token === ';') {
              $statements[strtolower($alias)] = $class;
              break;
            }
            else {
              break;
            }
          }
        }
      }
    }
  }
  return $statements;
}