This commit is contained in:
2020-10-21 11:04:34 +08:00
parent d3878cafa5
commit 0fed8bdece
+36 -13
View File
@@ -53,19 +53,19 @@ class Node extends Application
*/ */
public function bindHandler($handler) public function bindHandler($handler)
{ {
if ($handler instanceof Closure) { // if ($handler instanceof Closure) {
$this->handler = $handler; // $this->handler = $handler;
} else if (is_string($handler) && strpos($handler, '@') !== false) { // } else if (is_string($handler) && strpos($handler, '@') !== false) {
list($controller, $action) = explode('@', $handler); // list($controller, $action) = explode('@', $handler);
if (!empty($this->namespace)) { // if (!empty($this->namespace)) {
$controller = implode('\\', $this->namespace) . '\\' . $controller; // $controller = implode('\\', $this->namespace) . '\\' . $controller;
} // }
$this->handler = $this->getReflect($controller, $action); // $this->handler = $this->getReflect($controller, $action);
} 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.';
} else { // } else {
$this->handler = $handler; // }
} $this->handler = $handler;
return $this; return $this;
} }
@@ -395,9 +395,11 @@ class Node extends Application
*/ */
private function restructure() private function restructure()
{ {
$this->resolveHandler();
if (empty($this->handler)) { if (empty($this->handler)) {
return $this; return $this;
} }
/** @var Middleware $made */
$made = Snowflake::createObject(Middleware::class); $made = Snowflake::createObject(Middleware::class);
$made->setMiddleWares($this->middleware); $made->setMiddleWares($this->middleware);
$made->getGenerate($this); $made->getGenerate($this);
@@ -405,6 +407,27 @@ class Node extends Application
} }
/**
* @throws Exception
* 解析回调函数
*/
private function resolveHandler()
{
if ($this->handler instanceof \Closure) {
return;
}
if (is_string($this->handler) && strpos($this->handler, '@') !== false) {
list($controller, $action) = explode('@', $this->handler);
if (!empty($this->namespace)) {
$controller = implode('\\', $this->namespace) . '\\' . $controller;
}
$this->handler = $this->getReflect($controller, $action);
} else if ($this->handler != null && !is_callable($this->handler, true)) {
$this->_error = 'Controller is con\'t exec.';
}
}
/** /**
* @return mixed * @return mixed
* @throws Exception * @throws Exception