From eeb06cf623995026a6295122d602ba3014e07c09 Mon Sep 17 00:00:00 2001 From: whwyy Date: Mon, 18 Dec 2023 16:28:00 +0800 Subject: [PATCH] eee --- Scanner.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Scanner.php b/Scanner.php index 00da921..bbe9d11 100644 --- a/Scanner.php +++ b/Scanner.php @@ -9,6 +9,7 @@ use Kiri\Di\Inject\Container; use Kiri\Abstracts\Component; use Kiri\Di\Inject\Skip; use Psr\Container\ContainerInterface; +use ReflectionClass; use ReflectionMethod; class Scanner extends Component @@ -92,12 +93,8 @@ class Scanner extends Component if (class_exists($class)) { $reflect = $this->container->getReflectionClass($class); if ($reflect->isInstantiable()) { - $data = $reflect->getAttributes(Skip::class); - if (count($data) > 0) { - return; - } - $data = $reflect->getAttributes(\Attribute::class); - if (count($data) > 0) { + $attributes = $this->skipNames($reflect); + if (in_array(Skip::class, $attributes) || in_array(\Attribute::class, $attributes)) { return; } $object = $this->container->parse($class); @@ -117,4 +114,19 @@ class Scanner extends Component } } } + + + /** + * @param ReflectionClass $reflect + * @return array + */ + protected function skipNames(ReflectionClass $reflect): array + { + $attributes = $reflect->getAttributes(); + $names = []; + foreach ($attributes as $attribute) { + $names[] = $attribute->getName(); + } + return $names; + } }