If I am right currently the only solution to get the file of the class ReflectionClass::getFileName()
, parse the use
tokens and by traits and inheritance parse other files as well. After that you can create an alias map for the class, and use that alias map to get the absolute class names of the classes or interfaces we describe in the @return annotations. For example Doctrine TokenParser is an implementation of getting use statements by this approach...
So yes, it is possible to get the aliases, but there is no native support for annotations in php, so this is just a workaround...
A simple example:
use Doctrine\Common\Annotations\TokenParser;
use ReflectionClass;
function getAliases($className){
$annotatedClass = new ReflectionClass($className);
$namespace = $annotatedClass->getNamespaceName();
$aliases = array();
$classFile = $annotatedClass->getFileName();
if ($classFile) {
$classCode = file_get_contents($classFile);
$tokenParser = new TokenParser($classCode);
$aliases = $tokenParser->parseUseStatements($namespace);
return $aliases;
}
Returns
array(
strtolower($aliasName) => $className,
...
)