From 0a171da04714eb67b63e146ec99b83ee80661e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 3 Aug 2023 14:08:16 +0800 Subject: [PATCH] qqq --- Container.php | 18 ++++-------------- Scanner.php | 14 +++++++++++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Container.php b/Container.php index a98b69e..4a8d7a7 100644 --- a/Container.php +++ b/Container.php @@ -100,25 +100,15 @@ class Container implements ContainerInterface /** * @param string $id - * @return void + * @return object * @throws ReflectionException */ - public function parse(string $id): void + public function parse(string $id): object { if (isset($this->_singletons[$id])) { - return; - } - $object = $this->make($id); - $methods = $this->getReflectionClass($id); - foreach ($methods->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { - if ($method->isStatic() || $method->getDeclaringClass()->getName() != $id) { - continue; - } - $attributes = $method->getAttributes(); - foreach ($attributes as $attribute) { - $attribute->newInstance()->dispatch($object, $method->getName()); - } + return $this->_singletons[$id]; } + return $this->make($id); } diff --git a/Scanner.php b/Scanner.php index e1ea8e2..65bbf38 100644 --- a/Scanner.php +++ b/Scanner.php @@ -9,6 +9,7 @@ use Exception; use Kiri\Abstracts\Component; use Kiri\Di\Inject\Skip; use ReflectionException; +use ReflectionMethod; class Scanner extends Component { @@ -51,7 +52,18 @@ class Scanner extends Component if (count($data) > 0) { continue; } - $container->parse($class); + $object = $container->parse($class); + + $methods = $container->getReflectionClass($class); + foreach ($methods->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { + if ($method->isStatic() || $method->getDeclaringClass()->getName() != $class) { + continue; + } + $attributes = $method->getAttributes(); + foreach ($attributes as $attribute) { + $attribute->newInstance()->dispatch($object, $method->getName()); + } + } } } }