You are here

public function PhpParser::parseClass in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php \Doctrine\Common\Annotations\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

vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php, line 39

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());
  if (null === $content) {
    return array();
  }
  $namespace = preg_quote($class
    ->getNamespaceName());
  $content = preg_replace('/^.*?(\\bnamespace\\s+' . $namespace . '\\s*[;{].*)$/s', '\\1', $content);
  $tokenizer = new TokenParser('<?php ' . $content);
  $statements = $tokenizer
    ->parseUseStatements($class
    ->getNamespaceName());
  return $statements;
}