eee
This commit is contained in:
+4
-10
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Di\Interface;
|
||||
|
||||
interface InjectMethodInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(string $class, string $method): void;
|
||||
|
||||
}
|
||||
@@ -6,12 +6,12 @@ interface InjectProxyInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(string $fileName, object $class, string $method): void;
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param string $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(string $fileName, string $class, string $method): void;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Di\Interface;
|
||||
|
||||
interface InjectTargetInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(string $class): void;
|
||||
|
||||
}
|
||||
+1
-1
@@ -109,7 +109,7 @@ class Scanner extends Component
|
||||
if (!class_exists($attribute->getName())) {
|
||||
continue;
|
||||
}
|
||||
$attribute->newInstance()->dispatch($reflect, $method->getName());
|
||||
$attribute->newInstance()->dispatch($class, $method->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user