From ae8ba9ca4ec2c930eed26dd4272e6397f4a510f8 Mon Sep 17 00:00:00 2001 From: whwyy Date: Mon, 18 Dec 2023 22:23:16 +0800 Subject: [PATCH] eee --- Container.php | 14 ++++---------- Interface/InjectMethodInterface.php | 16 ++++++++++++++++ Interface/InjectProxyInterface.php | 14 +++++++------- Interface/InjectTargetInterface.php | 15 +++++++++++++++ Scanner.php | 2 +- 5 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 Interface/InjectMethodInterface.php create mode 100644 Interface/InjectTargetInterface.php diff --git a/Container.php b/Container.php index 8fe3fc9..0cb0e65 100644 --- a/Container.php +++ b/Container.php @@ -13,6 +13,7 @@ namespace Kiri\Di; use Closure; use Exception; use Kiri\Di\Interface\InjectProxyInterface; +use Kiri\Di\Interface\InjectTargetInterface; use Kiri\Router\Interface\ValidatorInterface; use Psr\Container\ContainerInterface; use ReflectionAttribute; @@ -212,10 +213,8 @@ class Container implements ContainerInterface foreach ($attributes as $attribute) { if (class_exists($attribute->getName())) { $instance = $attribute->newInstance(); - if ($object instanceof InjectProxyInterface) { - $instance->dispatch($reflect->getFileName(), $object); - } else { - $instance->dispatch($object); + if ($instance instanceof InjectTargetInterface) { + $instance->dispatch($object::class); } } } @@ -248,7 +247,6 @@ class Container implements ContainerInterface public function resolveProperties(ReflectionClass $reflectionClass, object $class): void { $properties = $reflectionClass->getProperties(); - $filename = $reflectionClass->getFileName(); foreach ($properties as $property) { $propertyAttributes = $property->getAttributes(); foreach ($propertyAttributes as $attribute) { @@ -256,11 +254,7 @@ class Container implements ContainerInterface continue; } $instance = $attribute->newInstance(); - if ($class instanceof InjectProxyInterface) { - $instance->dispatch($filename, $class, $property->getName()); - } else { - $instance->dispatch($class, $property->getName()); - } + $instance->dispatch($class::class, $property->getName()); } } } diff --git a/Interface/InjectMethodInterface.php b/Interface/InjectMethodInterface.php new file mode 100644 index 0000000..dc18e6b --- /dev/null +++ b/Interface/InjectMethodInterface.php @@ -0,0 +1,16 @@ +getName())) { continue; } - $attribute->newInstance()->dispatch($reflect, $method->getName()); + $attribute->newInstance()->dispatch($class, $method->getName()); } } }