diff --git a/core/Di/Container.php b/core/Di/Container.php index 9218858e..e643050e 100644 --- a/core/Di/Container.php +++ b/core/Di/Container.php @@ -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; } diff --git a/core/Di/NoteManager.php b/core/Di/NoteManager.php index ba5f4dd8..cf38f448 100644 --- a/core/Di/NoteManager.php +++ b/core/Di/NoteManager.php @@ -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)) { diff --git a/http-helper/Route/Node.php b/http-helper/Route/Node.php index 3625c986..39b87935 100644 --- a/http-helper/Route/Node.php +++ b/http-helper/Route/Node.php @@ -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; } diff --git a/http-helper/Route/Router.php b/http-helper/Route/Router.php index a71ab54b..4d365641 100644 --- a/http-helper/Route/Router.php +++ b/http-helper/Route/Router.php @@ -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; } diff --git a/http-server/Message/Request.php b/http-server/Message/Request.php index 261cab4a..972ce007 100644 --- a/http-server/Message/Request.php +++ b/http-server/Message/Request.php @@ -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; } diff --git a/note/Aspect.php b/note/Aspect.php index d63e9233..50761918 100644 --- a/note/Aspect.php +++ b/note/Aspect.php @@ -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 ');