You are here

public function TokenParser::parseUseStatement in Plug 7

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 lib/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php
Gets all use statements.

File

lib/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;
}