router->Branch_search($request); if (!($node instanceof Node)) { throw new RequestException(Constant::STATUS_404_MESSAGE, 404); } $psr7Response = $node->dispatch($request); if (!($psr7Response instanceof ResponseInterface)) { $psr7Response = $this->transferToResponse($psr7Response); } } catch (Error | \Throwable $exception) { $psr7Response = $this->exceptionHandler->emit($exception, $this->response); } finally { if (!isset($psr7Response)) { return; } $this->responseEmitter->sender($response, $psr7Response); $this->eventDispatch->dispatch(new OnAfterRequest()); } } /** * @param mixed $responseData * @return ResponseInterface * @throws Exception */ private function transferToResponse(mixed $responseData): ResponseInterface { $interface = $this->response->withStatus(200); if (!$interface->hasContentType()) { $interface->withContentType('application/json;charset=utf-8'); } $responseData = $interface->_toArray($responseData); if ($interface->getContentType() == 'application/xml;charset=utf-8') { $interface->getBody()->write(Help::toXml($responseData)); } else if (is_array($responseData)) { $interface->getBody()->write(json_encode($responseData)); } else { $interface->getBody()->write((string)$responseData); } return $interface; } /** * @param Server $server * @param int $fd * @throws Exception */ public function onDisconnect(Server $server, int $fd): void { } /** * @param Server $server * @param int $fd * @throws Exception */ public function onClose(Server $server, int $fd): void { } }