mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-04 04:37:46 +08:00
optimization code
This commit is contained in:
parent
99b3eefa81
commit
26a7c5975d
@ -205,8 +205,8 @@ class AnnotationReader implements Reader
|
||||
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
if (method_exists($class, 'getAttributes') && $attributes = $class->getAttributes()) {
|
||||
return array_map(fn(\ReflectionAttribute $attribute) => $attribute->newInstance(), $attributes);
|
||||
if ($annotations = $this->getPhp8Annotations($class)) {
|
||||
return $annotations;
|
||||
}
|
||||
$this->parser->setTarget(Target::TARGET_CLASS);
|
||||
$this->parser->setImports($this->getClassImports($class));
|
||||
@ -229,10 +229,18 @@ class AnnotationReader implements Reader
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPhp8Annotations(\Reflector $reflection): ?array
|
||||
{
|
||||
if (method_exists($reflection, 'getAttributes') && $attributes = $reflection->getAttributes()) {
|
||||
return array_map(fn(\ReflectionAttribute $attribute) => $attribute->newInstance(), $attributes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
if (method_exists($property, 'getAttributes') && $attributes = $property->getAttributes()) {
|
||||
return array_map(fn(\ReflectionAttribute $attribute) => $attribute->newInstance(), $attributes);
|
||||
if ($annotations = $this->getPhp8Annotations($property)) {
|
||||
return $annotations;
|
||||
}
|
||||
$class = $property->getDeclaringClass();
|
||||
$context = 'property ' . $class->getName() . '::$' . $property->getName();
|
||||
@ -260,8 +268,8 @@ class AnnotationReader implements Reader
|
||||
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
if (method_exists($method, 'getAttributes') && $attributes = $method->getAttributes()) {
|
||||
return array_map(fn(\ReflectionAttribute $attribute) => $attribute->newInstance(), $attributes);
|
||||
if ($annotations = $this->getPhp8Annotations($method)) {
|
||||
return $annotations;
|
||||
}
|
||||
$class = $method->getDeclaringClass();
|
||||
$context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
|
||||
|
Loading…
Reference in New Issue
Block a user