This commit is contained in:
2020-10-15 11:59:42 +08:00
parent fd9d88b97e
commit b467e04862
+5 -4
View File
@@ -390,19 +390,20 @@ class Node extends Application
/** /**
* @param string $class * @param string|\Closure $class
* @throws Exception * @throws Exception
*/ */
public function addMiddleware(string $class) public function addMiddleware($class)
{ {
if (!is_callable($class, true)) {
return;
}
if (is_string($class)) { if (is_string($class)) {
$class = Snowflake::createObject($class); $class = Snowflake::createObject($class);
if (!($class instanceof \HttpServer\IInterface\Middleware)) { if (!($class instanceof \HttpServer\IInterface\Middleware)) {
return; return;
} }
$class = [$class, 'handler']; $class = [$class, 'handler'];
} else if (!is_callable($class, true)) {
return;
} }
$this->middleware[] = $class; $this->middleware[] = $class;
$this->restructure(); $this->restructure();