111
This commit is contained in:
+22
-13
@@ -111,10 +111,29 @@ class Node
|
|||||||
$handler = $this->splitHandler($handler);
|
$handler = $this->splitHandler($handler);
|
||||||
} else if ($handler != null && !is_callable($handler, true)) {
|
} else if ($handler != null && !is_callable($handler, true)) {
|
||||||
$this->_error = 'Controller is con\'t exec.';
|
$this->_error = 'Controller is con\'t exec.';
|
||||||
}
|
|
||||||
$this->_handler[$method] = $handler;
|
|
||||||
return $this;
|
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
|
public function setParameters(): static
|
||||||
{
|
{
|
||||||
$container = Kiri::getDi();
|
|
||||||
if (empty($this->_handler)) {
|
if (empty($this->_handler)) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
foreach ($this->_handler as $method => $dispatcher) {
|
foreach ($this->_handler as $method => $dispatcher) {
|
||||||
if ($dispatcher instanceof Closure) {
|
$this->injectMiddleware($method, ...$dispatcher);
|
||||||
$_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->_handler = [];
|
$this->_handler = [];
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
Reference in New Issue
Block a user