modify plugin name
This commit is contained in:
+17
-36
@@ -12,7 +12,7 @@ namespace Kiri\Di;
|
|||||||
use Closure;
|
use Closure;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Psr\Container\ContainerInterface;
|
use Kiri\Di\ContainerInterface;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use ReflectionFunction;
|
use ReflectionFunction;
|
||||||
@@ -186,7 +186,7 @@ class Container implements ContainerInterface
|
|||||||
if ($construct->getNumberOfParameters() < 1) {
|
if ($construct->getNumberOfParameters() < 1) {
|
||||||
return $reflect->newInstance();
|
return $reflect->newInstance();
|
||||||
}
|
}
|
||||||
$parameters = $this->mergeParam($this->resolveMethodParameters($construct), $dependencies);
|
$parameters = $this->mergeParam($this->resolveParameters($construct), $dependencies);
|
||||||
return $reflect->newInstanceArgs($parameters);
|
return $reflect->newInstanceArgs($parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,10 +216,11 @@ class Container implements ContainerInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $className
|
* @param $className
|
||||||
* @param $method
|
* @param string|null $method
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function getMethodAttribute($className, $method = null): array
|
public function getMethodAttribute($className, ?string $method = null): array
|
||||||
{
|
{
|
||||||
return TargetManager::get($className)->getMethodAttribute($method);
|
return TargetManager::get($className)->getMethodAttribute($method);
|
||||||
}
|
}
|
||||||
@@ -229,6 +230,7 @@ class Container implements ContainerInterface
|
|||||||
* @param string $class
|
* @param string $class
|
||||||
* @param string|null $property
|
* @param string|null $property
|
||||||
* @return ReflectionProperty|ReflectionProperty[]|null
|
* @return ReflectionProperty|ReflectionProperty[]|null
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function getClassReflectionProperty(string $class, string $property = null): ReflectionProperty|null|array
|
public function getClassReflectionProperty(string $class, string $property = null): ReflectionProperty|null|array
|
||||||
{
|
{
|
||||||
@@ -286,6 +288,7 @@ class Container implements ContainerInterface
|
|||||||
* @param string $class
|
* @param string $class
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @return ReflectionMethod|null
|
* @return ReflectionMethod|null
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function getReflectMethod(string $class, string $method): ?ReflectionMethod
|
public function getReflectMethod(string $class, string $method): ?ReflectionMethod
|
||||||
{
|
{
|
||||||
@@ -294,13 +297,16 @@ class Container implements ContainerInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $className
|
* @param string|Closure $method
|
||||||
* @param string $method
|
* @param string|null $className
|
||||||
* @return array|null
|
* @return array|null
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function getMethodParameters(string $className, string $method): ?array
|
public function getArgs(string|Closure $method, ?string $className = null): ?array
|
||||||
{
|
{
|
||||||
|
if ($method instanceof Closure) {
|
||||||
|
return $this->resolveParameters(new ReflectionFunction($method));
|
||||||
|
}
|
||||||
if (isset($this->_parameters[$className]) && isset($this->_parameters[$className][$method])) {
|
if (isset($this->_parameters[$className]) && isset($this->_parameters[$className][$method])) {
|
||||||
return $this->_parameters[$className][$method];
|
return $this->_parameters[$className][$method];
|
||||||
}
|
}
|
||||||
@@ -309,10 +315,10 @@ class Container implements ContainerInterface
|
|||||||
throw new ReflectionException("Class does not have a function $className::$method");
|
throw new ReflectionException("Class does not have a function $className::$method");
|
||||||
}
|
}
|
||||||
$className = $reflectMethod->getDeclaringClass()->getName();
|
$className = $reflectMethod->getDeclaringClass()->getName();
|
||||||
if (isset($this->_parameters[$className]) && isset($this->_parameters[$className][$reflectMethod->getName()])) {
|
if (!isset($this->_parameters[$className]) || isset($this->_parameters[$className][$method])) {
|
||||||
return $this->_parameters[$className][$reflectMethod->getName()];
|
return $this->setParameters($className, $method, $this->resolveParameters($reflectMethod));
|
||||||
}
|
}
|
||||||
return $this->setParameters($className, $reflectMethod->getName(), $this->resolveMethodParameters($reflectMethod));
|
return $this->_parameters[$className][$method];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -331,22 +337,11 @@ class Container implements ContainerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Closure $reflectionMethod
|
|
||||||
* @return array
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
|
||||||
public function getFunctionParameters(Closure $reflectionMethod): array
|
|
||||||
{
|
|
||||||
return $this->resolveMethodParameters(new ReflectionFunction($reflectionMethod));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReflectionMethod|ReflectionFunction $reflectionMethod
|
* @param ReflectionMethod|ReflectionFunction $reflectionMethod
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function resolveMethodParameters(ReflectionMethod|ReflectionFunction $reflectionMethod): array
|
private function resolveParameters(ReflectionMethod|ReflectionFunction $reflectionMethod): array
|
||||||
{
|
{
|
||||||
if ($reflectionMethod->getNumberOfParameters() < 1) {
|
if ($reflectionMethod->getNumberOfParameters() < 1) {
|
||||||
return [];
|
return [];
|
||||||
@@ -387,20 +382,6 @@ class Container implements ContainerInterface
|
|||||||
return $this->_reflection[$class];
|
return $this->_reflection[$class];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $class
|
|
||||||
*/
|
|
||||||
public function unset($class)
|
|
||||||
{
|
|
||||||
if (is_array($class) && isset($class['class'])) {
|
|
||||||
$class = $class['class'];
|
|
||||||
} else if (is_object($class)) {
|
|
||||||
$class = $class::class;
|
|
||||||
}
|
|
||||||
unset(
|
|
||||||
$this->_reflection[$class], $this->_singletons[$class], $this->_constructs[$class]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return $this
|
* @return $this
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Kiri\Di;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @mixin Container
|
||||||
|
*/
|
||||||
|
interface ContainerInterface extends \Psr\Container\ContainerInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -90,7 +90,7 @@ class Target
|
|||||||
* @return null|array
|
* @return null|array
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
#[Pure] public function getSpecify_annotation(string $method, string $annotation): ?array
|
#[Pure] public function searchNote(string $method, string $annotation): ?array
|
||||||
{
|
{
|
||||||
$data = $this->getMethodAttribute($method, $annotation);
|
$data = $this->getMethodAttribute($method, $annotation);
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user