From 0ec4dd9611169230cb0d25e5bb8ca9a7cc30c8b2 Mon Sep 17 00:00:00 2001 From: Jagepard Date: Tue, 20 May 2025 22:25:31 +0300 Subject: [PATCH] adds reflectionCache --- src/Router.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Router.php b/src/Router.php index bb39734..008840c 100755 --- a/src/Router.php +++ b/src/Router.php @@ -20,6 +20,8 @@ class Router implements RouterInterface use SetRudraContainersTrait; use RouterRequestMethodTrait; + protected array $reflectionCache = []; + /** * @param array $route * @return void @@ -198,11 +200,15 @@ protected function callActionThroughReflection(?array $params, string $action, o throw new RouterException("404"); } - $reflection = new \ReflectionClass($controller); - $method = $reflection->getMethod($action); + $cacheKey = get_class($controller) . "::$action"; + if (!isset($this->reflectionCache[$cacheKey])) { + $this->reflectionCache[$cacheKey] = [ + 'method' => new \ReflectionMethod($controller, $action), + ]; + } + $method = $this->reflectionCache[$cacheKey]['method']; $arguments = $this->rudra()->getParamsIoC($method, $params); - $method->invokeArgs($controller, $arguments); }