responseEmitter = $this->response->emmit; $exception = \config('request.exception'); if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) { $exception = ExceptionHandlerDispatcher::class; } $this->exception = $this->container->get($exception); $this->router = $this->dataGrip->get(ROUTER_TYPE_HTTP); } /** * @param Request $request * @param Response $response * @throws Exception */ public function onRequest(Request $request, Response $response): void { /** @var CQ $PsrRequest */ try { $PsrRequest = $this->initRequestAndResponse($request); $PsrResponse = $this->router->query($request->server['path_info'], $request->getMethod()) ->run($PsrRequest); } catch (Throwable $throwable) { $PsrResponse = $this->exception->emit($throwable, $this->constrictResponse); } finally { $this->responseEmitter->response($PsrResponse, $response, $PsrRequest); } } /** * @param Request $request * @return ServerRequestInterface */ public function initRequestAndResponse(Request $request): ServerRequestInterface { $response = new ConstrictResponse($this->response->contentType); Context::set(ResponseInterface::class, $response); return Context::set(RequestInterface::class, CQ::builder($request)); } }