Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Router implements RouterInterface
use SetRudraContainersTrait;
use RouterRequestMethodTrait;

protected array $reflectionCache = [];

/**
* @param array $route
* @return void
Expand Down Expand Up @@ -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);
}

Expand Down
Loading