responseEmitter = $this->response->emmit; $exception = \config('components.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 { try { /** @var ConstrictRequest $PsrRequest */ $PsrRequest = Context::set(RequestInterface::class, $this->createConstrictRequest($request)); /** @var ConstrictResponse $PsrResponse */ Context::set(ResponseInterface::class, new ConstrictResponse($this->response->contentType)); /** @var $PsrResponse */ $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 ConstrictRequest */ protected function createConstrictRequest(Request $request): ConstrictRequest { return (new ConstrictRequest())->withHeaders($request->header ?? []) ->withUri(new Uri($request)) ->withProtocolVersion($request->server['server_protocol']) ->withCookieParams($request->cookie ?? []) ->withServerParams($request->server) ->withQueryParams($request->get ?? []) ->withBody(new Stream($request->getContent())) ->withParsedBody($request) ->withUploadedFiles($request->files ?? []) ->withMethod($request->getMethod()); } }