This commit is contained in:
2021-07-27 16:08:16 +08:00
parent ef423dc1b8
commit a36f876792
8 changed files with 744 additions and 748 deletions
+20 -2
View File
@@ -94,8 +94,26 @@ class Node extends HttpService
} else {
$this->handler = $handler;
}
if (!empty($this->handler) && is_array($this->handler)) {
$this->callback = di(MiddlewareManager::class)->callerMiddlewares(
return $this->injectMiddleware();
}
/**
* @throws NotFindClassException
* @throws ReflectionException
*/
private function injectMiddleware(): static
{
$manager = di(MiddlewareManager::class);
if ($this->handler instanceof Closure) {
if (!empty($this->middleware)) {
$this->callback = $manager->closureMiddlewares($this->middleware, $this->createDispatch());
} else {
$this->callback = $this->createDispatch();
}
} else {
$manager->addMiddlewares($this->handler[0], $this->handler[1], $this->middleware);
$this->callback = $manager->callerMiddlewares(
$this->handler[0], $this->handler[1], $this->createDispatch()
);
}