This commit is contained in:
as2252258@163.com
2021-09-04 17:06:05 +08:00
parent 8f919ffa1b
commit 7d26617092
6 changed files with 27 additions and 30 deletions
+5 -19
View File
@@ -68,13 +68,6 @@ class Container extends BaseObject implements ContainerInterface
];
/**
* @var array
*
* The construct parameter
*/
private array $_param = [];
/**
* @param $class
* @param array $constrict
@@ -270,10 +263,7 @@ class Container extends BaseObject implements ContainerInterface
if ($reflect->isAbstract() || $reflect->isTrait() || $reflect->isInterface()) {
return $this->_reflection[$class] = $reflect;
}
NoteManager::setPropertyNote($reflect);
NoteManager::setTargetNote($reflect);
NoteManager::setMethodNote($reflect);
$construct = $reflect->getConstructor();
$construct = NoteManager::resolveTarget($reflect);
if (!empty($construct) && $construct->getNumberOfParameters() > 0) {
$this->_constructs[$class] = $construct;
}
@@ -313,14 +303,12 @@ class Container extends BaseObject implements ContainerInterface
* @return array|null
* @throws ReflectionException
*/
public function getMethodParameters(ReflectionClass|string $class, string $method): ?array
public function getMethodParameters(string $className, string $method): ?array
{
$className = $class;
if (is_object($class)) $className = $class->getName();
if (isset($this->_parameters[$className]) && isset($this->_parameters[$className][$method])) {
return $this->_parameters[$className][$method];
}
$reflectMethod = $this->getReflectMethod($class, $method);
$reflectMethod = $this->getReflectMethod($this->getReflect($className), $method);
if (!($reflectMethod instanceof ReflectionMethod)) {
throw new ReflectionException("Class does not have a function $className::$method");
}
@@ -355,7 +343,7 @@ class Container extends BaseObject implements ContainerInterface
* @return array
* @throws ReflectionException
*/
public function resolveFunctionParameters(Closure $reflectionMethod): array
public function getFunctionParameters(Closure $reflectionMethod): array
{
return $this->resolveMethodParameters(new ReflectionFunction($reflectionMethod));
}
@@ -419,8 +407,7 @@ class Container extends BaseObject implements ContainerInterface
$class = $class::class;
}
unset(
$this->_reflection[$class], $this->_singletons[$class],
$this->_param[$class], $this->_constructs[$class]
$this->_reflection[$class], $this->_singletons[$class], $this->_constructs[$class]
);
}
@@ -431,7 +418,6 @@ class Container extends BaseObject implements ContainerInterface
{
$this->_reflection = [];
$this->_singletons = [];
$this->_param = [];
$this->_constructs = [];
return $this;
}
+15 -1
View File
@@ -151,6 +151,20 @@ class NoteManager
}
/**
* @param \ReflectionClass $reflect
* @return \ReflectionMethod|null
*/
public static function resolveTarget(ReflectionClass $reflect): ?\ReflectionMethod
{
NoteManager::setPropertyNote($reflect);
NoteManager::setTargetNote($reflect);
NoteManager::setMethodNote($reflect);
return $reflect->getConstructor();
}
/**
* @param ReflectionClass $class
*/
@@ -197,7 +211,7 @@ class NoteManager
* @param string|null $method
* @return array
*/
public static function getMethodByAnnotation(string $attribute, string $class, string $method = null): mixed
public static function getSpecify_annotation(string $attribute, string $class, string $method = null): mixed
{
$class = self::getAttributeTrees($attribute, $class);
if (empty($class) || !isset($class['method']) || empty($method)) {
+2 -2
View File
@@ -212,7 +212,7 @@ class Node
}
foreach ($this->_handler as $method => $dispatcher) {
if ($dispatcher instanceof Closure) {
$_injectParameters = $container->resolveFunctionParameters($dispatcher);
$_injectParameters = $container->getFunctionParameters($dispatcher);
} else {
[$controller, $action] = $dispatcher;
if (is_object($controller)) {
@@ -256,7 +256,7 @@ class Node
}
/** @var Aspect $aspect */
$aspect = NoteManager::getMethodByAnnotation(Aspect::class, $controller, $action);
$aspect = NoteManager::getSpecify_annotation(Aspect::class, $controller, $action);
if (empty($aspect)) {
return null;
}
+1 -1
View File
@@ -57,7 +57,7 @@ class Router extends HttpService implements RouterInterface
/**
* @param Closure $middleware
*/
public function setMiddleware(\Closure $middleware): void
public function setMiddleware(Closure $middleware): void
{
$this->middleware = $middleware;
}
+4 -4
View File
@@ -218,10 +218,10 @@ class Request implements RequestInterface
}
/**
* @return UriInterface
*/
public function getUri(): UriInterface
/**
* @return \Server\Message\Uri|\Psr\Http\Message\UriInterface
*/
public function getUri(): Uri|UriInterface
{
return $this->uri;
}
-3
View File
@@ -5,9 +5,6 @@ namespace Annotation;
use Exception;
use Kiri\AspectManager;
use Kiri\IAspect;
use Kiri\Kiri;
defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implement ');