dataGrip = $dataGrip; $this->responseEmitter = $this->response->emmit; $exception = \config('servers.request.exception'); if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) { $exception = ExceptionHandlerDispatcher::class; } $this->exception = \Kiri::getDi()->get($exception); $this->router = $dataGrip->get(ROUTER_TYPE_HTTP); } /** * @param Request $request * @param Response $response * @throws */ public function onRequest(Request $request, Response $response): void { try { $this->setResponseHeaders($response, $this->response->headers); /** @var CQ $PsrRequest */ Context::set(ResponseInterface::class, new ConstrictResponse($this->response->contentType)); $PsrRequest = Context::set(RequestInterface::class, CQ::builder($request)); $this->router = $this->dataGrip->get(ROUTER_TYPE_HTTP); CoordinatorManager::utility(Coordinator::WORKER_START)->yield(); $PsrResponse = $this->router->query($request->server['path_info'], $request->getMethod())->run($PsrRequest); } catch (Throwable $throwable) { \Kiri::getLogger()->json_log($throwable); $PsrResponse = $this->exception->emit($throwable, $this->constrictResponse); } finally { $this->responseEmitter->response($PsrResponse, $response, $PsrRequest); } } /** * @param Response $response * @param array $headers * @return void */ protected function setResponseHeaders(Response $response, array $headers): void { foreach ($headers as $key => $header) { $response->header($key, $header); } } }