handler = $handler; $class->request = $request; if ($handler instanceof Closure) { $class->bind(); } $class->bindParam(); return $class; } /** * @return mixed * 执行函数 * @throws \Exception */ public function dispatch(): mixed { return \aop($this->handler, ...func_get_args()); } /** * @throws ReflectionException * @throws NotFindClassException */ protected function bind() { $class = $this->bindRequest(Snowflake::createObject(Controller::class)); $this->handler = Closure::bind($this->handler, $class); } /** * @param $controller * @return mixed */ protected function bindRequest($controller): mixed { $controller->request = Context::getContext('request'); $controller->headers = $controller->request?->headers; $controller->input = $controller->request?->params; return $controller; } /** * 参数绑定 */ protected function bindParam() { if ($this->handler instanceof Closure) { return; } $controller = $this->handler[0]; $this->bindRequest($controller); } }