public function PhpParser::parseClass

Parses a class.

Parameters

\ReflectionClass $class A <code>ReflectionClass</code> object.:

Return value

array A list with use statements in the form (Alias => FQN).

File

drupal/core/vendor/doctrine/common/lib/Doctrine/Common/Annotations/PhpParser.php, line 38

Class

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

Namespace

Doctrine\Common\Annotations

Code

public function parseClass(\ReflectionClass $class) {
  if (method_exists($class, 'getUseStatements')) {
    return $class
      ->getUseStatements();
  }
  if (false === ($filename = $class
    ->getFilename())) {
    return array();
  }
  $content = $this
    ->getFileContent($filename, $class
    ->getStartLine());
  $namespace = str_replace('\\', '\\\\', $class
    ->getNamespaceName());
  $content = preg_replace('/^.*?(\\bnamespace\\s+' . $namespace . '\\s*[;{].*)$/s', '\\1', $content);
  $tokenizer = new TokenParser('<?php ' . $content);
  $statements = $tokenizer
    ->parseUseStatements($class
    ->getNamespaceName());
  return $statements;
}