变更
This commit is contained in:
+12
-2
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Di;
|
namespace Kiri\Di;
|
||||||
|
|
||||||
|
|
||||||
|
use Kiri\Di\Interface\InjectProxyInterface;
|
||||||
use Kiri\Router\Interface\ValidatorInterface;
|
use Kiri\Router\Interface\ValidatorInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
@@ -185,8 +186,12 @@ class Container implements ContainerInterface
|
|||||||
if (!class_exists($attribute->getName())) {
|
if (!class_exists($attribute->getName())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($object instanceof InjectProxyInterface) {
|
||||||
|
$attribute->newInstance()->dispatch($reflect->getFileName(), $object);
|
||||||
|
} else {
|
||||||
$attribute->newInstance()->dispatch($object);
|
$attribute->newInstance()->dispatch($object);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->resolveProperties($reflect, $object);
|
$this->resolveProperties($reflect, $object);
|
||||||
if (method_exists($object, 'init') && $object::class !== 'Symfony\Component\Console\Application') {
|
if (method_exists($object, 'init') && $object::class !== 'Symfony\Component\Console\Application') {
|
||||||
@@ -204,18 +209,23 @@ class Container implements ContainerInterface
|
|||||||
public function resolveProperties(ReflectionClass $getReflectionClass, object $class): void
|
public function resolveProperties(ReflectionClass $getReflectionClass, object $class): void
|
||||||
{
|
{
|
||||||
$properties = $getReflectionClass->getProperties();
|
$properties = $getReflectionClass->getProperties();
|
||||||
|
|
||||||
|
$filename = $getReflectionClass->getFileName();
|
||||||
foreach ($properties as $property) {
|
foreach ($properties as $property) {
|
||||||
$propertyAttributes = $property->getAttributes();
|
$propertyAttributes = $property->getAttributes();
|
||||||
|
|
||||||
foreach ($propertyAttributes as $attribute) {
|
foreach ($propertyAttributes as $attribute) {
|
||||||
if (!class_exists($attribute->getName()) ||
|
if (!class_exists($attribute->getName()) ||
|
||||||
in_array(ValidatorInterface::class, class_implements($attribute->getName()))) {
|
in_array(ValidatorInterface::class, class_implements($attribute->getName()))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($class instanceof InjectProxyInterface) {
|
||||||
|
$attribute->newInstance()->dispatch($filename, $class, $property->getName());
|
||||||
|
} else {
|
||||||
$attribute->newInstance()->dispatch($class, $property->getName());
|
$attribute->newInstance()->dispatch($class, $property->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -280,7 +290,7 @@ class Container implements ContainerInterface
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
private function resolveMethodParams(ReflectionMethod|ReflectionFunction $parameters): array
|
public function resolveMethodParams(ReflectionMethod|ReflectionFunction $parameters): array
|
||||||
{
|
{
|
||||||
$params = [];
|
$params = [];
|
||||||
if ($parameters->getNumberOfParameters() < 1) {
|
if ($parameters->getNumberOfParameters() < 1) {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Kiri\Di\Interface;
|
||||||
|
|
||||||
|
interface InjectProxyInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fileName
|
||||||
|
* @param object $class
|
||||||
|
* @param string $method
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function dispatch(string $fileName, object $class, string $method): void;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user