optimization code

This commit is contained in:
assert 2021-06-13 18:12:04 +08:00 committed by 李铭昕
parent 99b3eefa81
commit 26a7c5975d

View File

@ -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() . '()';