From edfe966e83ed32b54a81447aa52661a37d3d53db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Sun, 16 Apr 2023 16:58:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Container.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Container.php b/Container.php index d584467..83b7a2d 100644 --- a/Container.php +++ b/Container.php @@ -168,13 +168,24 @@ class Container implements ContainerInterface $object = self::configure($reflect->newInstanceArgs($construct), $config); + return $this->inject($object, $reflect); + } + + + /** + * @param object $object + * @param ReflectionClass $reflect + * @return object + */ + private function inject(object $object, ReflectionClass $reflect): object + { $targetAttributes = $reflect->getAttributes(); foreach ($targetAttributes as $attribute) { $attribute->newInstance()->dispatch($object); } $this->resolveProperties($reflect, $object); - if (method_exists($object, 'init') && $className !== 'Symfony\Component\Console\Application') { + if (method_exists($object, 'init') && $object::class !== 'Symfony\Component\Console\Application') { call_user_func([$object, 'init']); } return $object;