function PhpParser::parseUseStatements
Parse a class or function for use statements.
@psalm-return array<string, string> a list with use statements in the form (Alias => FQN).
Parameters
ReflectionClass|ReflectionFunction $reflection:
File
-
vendor/
doctrine/ annotations/ lib/ Doctrine/ Common/ Annotations/ PhpParser.php, line 26
Class
- PhpParser
- Parses a file for namespaces/use/class declarations.
Namespace
Doctrine\Common\AnnotationsCode
public function parseUseStatements($reflection) : array {
if (method_exists($reflection, 'getUseStatements')) {
return $reflection->getUseStatements();
}
$filename = $reflection->getFileName();
if ($filename === false) {
return [];
}
$content = $this->getFileContent($filename, $reflection->getStartLine());
if ($content === null) {
return [];
}
$namespace = preg_quote($reflection->getNamespaceName());
$content = preg_replace('/^.*?(\\bnamespace\\s+' . $namespace . '\\s*[;{].*)$/s', '\\1', $content);
$tokenizer = new TokenParser('<?php ' . $content);
return $tokenizer->parseUseStatements($reflection->getNamespaceName());
}