diff --git a/src/Bean/Parser/BeanParser.php b/src/Bean/Parser/BeanParser.php index 51b1fdc853..25b7b35d35 100644 --- a/src/Bean/Parser/BeanParser.php +++ b/src/Bean/Parser/BeanParser.php @@ -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 { @@ -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); - $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 + $docblock = DocBlock::getDocBlock($comment, new Context($propRef->getDeclaringClass()->getNamespaceName())); + $tag = $docblock->getTagsWithTypeByName('var')[0] ?? null; + if ($tag) { - $tmpClassName = Imi::getClassNamespace($className) . '\\' . $name; - if (class_exists($tmpClassName)) - { - $annotation->name = $tmpClassName; - } - else - { - $annotation->name = $name; - } + $annotation->name = $tag->getType()->__toString(); } } - else - { - throw new \RuntimeException(sprintf('@%s in %s::$%s must set name', $annotationClass, $className, $target)); - } } break; } diff --git a/src/Components/grpc/src/Util/GrpcInterfaceManager.php b/src/Components/grpc/src/Util/GrpcInterfaceManager.php index 597d8d18da..2a9dcef492 100644 --- a/src/Components/grpc/src/Util/GrpcInterfaceManager.php +++ b/src/Components/grpc/src/Util/GrpcInterfaceManager.php @@ -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) @@ -93,9 +94,8 @@ public function bind($interface, ?string $serviceName = null): void } else { - $docblock = DocBlock::getDocBlock($docComment); - // @phpstan-ignore-next-line - $responseClass = (string) $docblock->getTagsByName('return')[0]->getType(); + $docblock = DocBlock::getDocBlock($docComment, new Context($interface->getNamespaceName())); + $responseClass = (string) $docblock->getTagsWithTypeByName('return')[0]->getType(); } $methods[$method->getName()] = [