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 $class
* @param array $constrict * @param array $constrict
@@ -270,10 +263,7 @@ class Container extends BaseObject implements ContainerInterface
if ($reflect->isAbstract() || $reflect->isTrait() || $reflect->isInterface()) { if ($reflect->isAbstract() || $reflect->isTrait() || $reflect->isInterface()) {
return $this->_reflection[$class] = $reflect; return $this->_reflection[$class] = $reflect;
} }
NoteManager::setPropertyNote($reflect); $construct = NoteManager::resolveTarget($reflect);
NoteManager::setTargetNote($reflect);
NoteManager::setMethodNote($reflect);
$construct = $reflect->getConstructor();
if (!empty($construct) && $construct->getNumberOfParameters() > 0) { if (!empty($construct) && $construct->getNumberOfParameters() > 0) {
$this->_constructs[$class] = $construct; $this->_constructs[$class] = $construct;
} }
@@ -313,14 +303,12 @@ class Container extends BaseObject implements ContainerInterface
* @return array|null * @return array|null
* @throws ReflectionException * @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])) { if (isset($this->_parameters[$className]) && isset($this->_parameters[$className][$method])) {
return $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)) { if (!($reflectMethod instanceof ReflectionMethod)) {
throw new ReflectionException("Class does not have a function $className::$method"); throw new ReflectionException("Class does not have a function $className::$method");
} }
@@ -355,7 +343,7 @@ class Container extends BaseObject implements ContainerInterface
* @return array * @return array
* @throws ReflectionException * @throws ReflectionException
*/ */
public function resolveFunctionParameters(Closure $reflectionMethod): array public function getFunctionParameters(Closure $reflectionMethod): array
{ {
return $this->resolveMethodParameters(new ReflectionFunction($reflectionMethod)); return $this->resolveMethodParameters(new ReflectionFunction($reflectionMethod));
} }
@@ -419,8 +407,7 @@ class Container extends BaseObject implements ContainerInterface
$class = $class::class; $class = $class::class;
} }
unset( unset(
$this->_reflection[$class], $this->_singletons[$class], $this->_reflection[$class], $this->_singletons[$class], $this->_constructs[$class]
$this->_param[$class], $this->_constructs[$class]
); );
} }
@@ -431,7 +418,6 @@ class Container extends BaseObject implements ContainerInterface
{ {
$this->_reflection = []; $this->_reflection = [];
$this->_singletons = []; $this->_singletons = [];
$this->_param = [];
$this->_constructs = []; $this->_constructs = [];
return $this; 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 * @param ReflectionClass $class
*/ */
@@ -197,7 +211,7 @@ class NoteManager
* @param string|null $method * @param string|null $method
* @return array * @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); $class = self::getAttributeTrees($attribute, $class);
if (empty($class) || !isset($class['method']) || empty($method)) { if (empty($class) || !isset($class['method']) || empty($method)) {
+2 -2
View File
@@ -212,7 +212,7 @@ class Node
} }
foreach ($this->_handler as $method => $dispatcher) { foreach ($this->_handler as $method => $dispatcher) {
if ($dispatcher instanceof Closure) { if ($dispatcher instanceof Closure) {
$_injectParameters = $container->resolveFunctionParameters($dispatcher); $_injectParameters = $container->getFunctionParameters($dispatcher);
} else { } else {
[$controller, $action] = $dispatcher; [$controller, $action] = $dispatcher;
if (is_object($controller)) { if (is_object($controller)) {
@@ -256,7 +256,7 @@ class Node
} }
/** @var Aspect $aspect */ /** @var Aspect $aspect */
$aspect = NoteManager::getMethodByAnnotation(Aspect::class, $controller, $action); $aspect = NoteManager::getSpecify_annotation(Aspect::class, $controller, $action);
if (empty($aspect)) { if (empty($aspect)) {
return null; return null;
} }
+1 -1
View File
@@ -57,7 +57,7 @@ class Router extends HttpService implements RouterInterface
/** /**
* @param Closure $middleware * @param Closure $middleware
*/ */
public function setMiddleware(\Closure $middleware): void public function setMiddleware(Closure $middleware): void
{ {
$this->middleware = $middleware; $this->middleware = $middleware;
} }
+2 -2
View File
@@ -219,9 +219,9 @@ class Request implements RequestInterface
/** /**
* @return UriInterface * @return \Server\Message\Uri|\Psr\Http\Message\UriInterface
*/ */
public function getUri(): UriInterface public function getUri(): Uri|UriInterface
{ {
return $this->uri; return $this->uri;
} }
-3
View File
@@ -5,9 +5,6 @@ namespace Annotation;
use Exception; use Exception;
use Kiri\AspectManager;
use Kiri\IAspect;
use Kiri\Kiri;
defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implement '); defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implement ');