变更
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di;
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Kiri\Di\Context;
|
||||
|
||||
class AsyncContext implements ContextInterface
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di\Context;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di\Context;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di\Inject;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di\Inject;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Kiri\Di\Inject;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di\Inject;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Kiri\Di\Inject;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di\Interface;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di\Interface;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di\Interface;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Di;
|
||||
|
||||
|
||||
-142
@@ -1,142 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Di;
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use ReflectionAttribute;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
class Target
|
||||
{
|
||||
|
||||
|
||||
private ReflectionClass $target;
|
||||
|
||||
|
||||
private array $methods = [];
|
||||
|
||||
|
||||
private array $property = [];
|
||||
|
||||
|
||||
private mixed $construct = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $target
|
||||
*/
|
||||
public function __construct(ReflectionClass $target)
|
||||
{
|
||||
$this->target = $target;
|
||||
$this->construct = $target->getConstructor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed|ReflectionMethod|null
|
||||
*/
|
||||
public function getConstruct(): mixed
|
||||
{
|
||||
return $this->construct;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ReflectionAttribute[]
|
||||
*/
|
||||
#[Pure] public function getAttributes(): array
|
||||
{
|
||||
return $this->target->getAttributes();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $property
|
||||
* @return ReflectionProperty
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
#[Pure] public function getProperty(string $property): ReflectionProperty
|
||||
{
|
||||
return $this->target->getProperty($property);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array<string, ReflectionMethod>
|
||||
*/
|
||||
#[Pure] public function getMethods(): array
|
||||
{
|
||||
return $this->target->getMethods();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @return ReflectionMethod
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
#[Pure] public function getMethod(string $method): ReflectionMethod
|
||||
{
|
||||
return $this->target->getMethod($method);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $annotation
|
||||
* @return null|array
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
#[Pure] public function searchNote(string $method, string $annotation): ?array
|
||||
{
|
||||
$data = $this->getMethodAttribute($method, $annotation);
|
||||
if (!empty($data)) {
|
||||
return $data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
#[Pure] public function getMethodsAttribute(): array
|
||||
{
|
||||
$methods = $this->target->getMethods();
|
||||
|
||||
$array = [];
|
||||
foreach ($methods as $method) {
|
||||
$array[$method->getName()] = $this->getMethodAttribute($method->getName());
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ReflectionProperty[]
|
||||
*/
|
||||
#[Pure] public function getPropertyAttribute(): array
|
||||
{
|
||||
return $this->target->getProperties(ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PUBLIC);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $property
|
||||
* @param string|null $annotation
|
||||
* @return array|ReflectionAttribute
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
#[Pure] public function getMethodAttribute(string $property, ?string $annotation = null): array|ReflectionAttribute
|
||||
{
|
||||
$attributes = $this->target->getMethod($property);
|
||||
if (!empty($annotation)) {
|
||||
return $attributes->getAttributes($annotation);
|
||||
}
|
||||
return $attributes->getAttributes();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Di;
|
||||
|
||||
class TargetManager
|
||||
{
|
||||
|
||||
|
||||
private static array $targets = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @return Target|null
|
||||
*/
|
||||
public static function get(string $class): ?Target
|
||||
{
|
||||
return static::$targets[$class] ?? null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @return bool
|
||||
*/
|
||||
public static function has(string $class): bool
|
||||
{
|
||||
return isset(static::$targets[$class]) && static::$targets[$class] !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param \ReflectionClass $reflection
|
||||
* @return Target
|
||||
*/
|
||||
public static function set(string $class, \ReflectionClass $reflection): Target
|
||||
{
|
||||
$target = new Target($reflection);
|
||||
|
||||
static::$targets[$class] = $target;
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user