This commit is contained in:
as2252258@163.com
2021-09-05 02:51:53 +08:00
parent f19f0c0e81
commit 8735203573
+22 -13
View File
@@ -111,10 +111,29 @@ class Node
$handler = $this->splitHandler($handler);
} else if ($handler != null && !is_callable($handler, true)) {
$this->_error = 'Controller is con\'t exec.';
}
$this->_handler[$method] = $handler;
return $this;
}
$this->_handler[$method] = [$handler, $this->resolveMethodParams($handler)];
return $this;
}
/**
* @param $dispatcher
* @return array
* @throws \ReflectionException
*/
private function resolveMethodParams($dispatcher): array
{
$container = Kiri::getDi();
if ($dispatcher instanceof Closure) {
$_injectParameters = $container->getFunctionParameters($dispatcher);
} else {
$_injectParameters = $container->getMethodParameters(
$dispatcher[0]::class, $dispatcher[1]);
}
return $_injectParameters;
}
/**
@@ -206,21 +225,11 @@ class Node
*/
public function setParameters(): static
{
$container = Kiri::getDi();
if (empty($this->_handler)) {
return $this;
}
foreach ($this->_handler as $method => $dispatcher) {
if ($dispatcher instanceof Closure) {
$_injectParameters = $container->getFunctionParameters($dispatcher);
} else {
[$controller, $action] = $dispatcher;
if (is_object($controller)) {
$controller = get_class($controller);
}
$_injectParameters = $container->getMethodParameters($controller, $action);
}
$this->injectMiddleware($method, $dispatcher, $_injectParameters);
$this->injectMiddleware($method, ...$dispatcher);
}
$this->_handler = [];
return $this;