Skip to content

Commit

Permalink
修复对注释 var 类型的解析
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Apr 22, 2024
1 parent afb2950 commit ce1c083
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
34 changes: 5 additions & 29 deletions src/Bean/Parser/BeanParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
use Imi\Bean\ReflectionContainer;
use Imi\Server\Annotation\ServerInject;
use Imi\Util\DocBlock;
use Imi\Util\Imi;
use Yurun\Doctrine\Common\Annotations\PhpParser;
use phpDocumentor\Reflection\Types\Context;

class BeanParser extends BaseParser
{
Expand Down Expand Up @@ -62,40 +61,17 @@ public function parse(\Imi\Bean\Annotation\Base $annotation, string $className,
$comment = $propRef->getDocComment();
if (false === $comment)
{
$tag = null;
throw new \RuntimeException(sprintf('@%s in %s::$%s must set name', $annotationClass, $className, $target));
}
else
{
$docblock = DocBlock::getDocBlock($comment);
$docblock = DocBlock::getDocBlock($comment, new Context($propRef->getDeclaringClass()->getNamespaceName()));
$tag = $docblock->getTagsByName('var')[0] ?? null;
}
if ($tag)
{
$name = trim($tag->__toString(), '\\ \t\n\r\0\x0B');
$phpParser = new PhpParser();
$uses = $phpParser->parseClass(ReflectionContainer::getClassReflection($className));
$lowerName = strtolower($name);
if (isset($uses[$lowerName]))
{
$annotation->name = $uses[$lowerName];
}
else
if ($tag)
{
$tmpClassName = Imi::getClassNamespace($className) . '\\' . $name;
if (class_exists($tmpClassName))
{
$annotation->name = $tmpClassName;
}
else
{
$annotation->name = $name;
}
$annotation->name = $tag[0]->getType()->__toString();
}
}
else
{
throw new \RuntimeException(sprintf('@%s in %s::$%s must set name', $annotationClass, $className, $target));
}
}
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Components/grpc/src/Util/GrpcInterfaceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Imi\Bean\ReflectionUtil;
use Imi\Server\Http\Route\Annotation\Controller;
use Imi\Util\DocBlock;
use phpDocumentor\Reflection\Types\Context;

/**
* @Bean(name="GrpcInterfaceManager", recursion=false)
Expand Down Expand Up @@ -93,7 +94,7 @@ public function bind($interface, ?string $serviceName = null): void
}
else
{
$docblock = DocBlock::getDocBlock($docComment);
$docblock = DocBlock::getDocBlock($docComment, new Context($interface->getNamespaceName()));
// @phpstan-ignore-next-line
$responseClass = (string) $docblock->getTagsByName('return')[0]->getType();
}
Expand Down

0 comments on commit ce1c083

Please sign in to comment.