router->Branch_search($request);
// if (!($node instanceof Node)) {
// throw new RequestException('
HTTP 404 Not Found
Powered by Swoole', 404);
// }
// if (!(($responseData = $node->dispatch($request)) instanceof ResponseInterface)) {
// $responseData = $this->transferToResponse($responseData);
// }
$responseData = $this->transferToResponse('hello word.');
} catch (Error | \Throwable $exception) {
$responseData = $this->exceptionHandler->emit($exception, $this->response);
} finally {
$this->responseEmitter->sender($response, $responseData);
$this->eventDispatch->dispatch(new OnAfterRequest());
}
}
/**
* @param mixed $responseData
* @return ResponseInterface
* @throws Exception
*/
private function transferToResponse(mixed $responseData): mixed
{
$interface = $this->response->withStatus(200);
if (!$interface->hasContentType()) {
$interface->withContentType(MsgResponse::CONTENT_TYPE_JSON);
}
$responseData = $interface->_toArray($responseData);
if ($interface->getContentType() == MsgResponse::CONTENT_TYPE_XML) {
$interface->stream->write(Help::toXml($responseData));
} else if (is_array($responseData)) {
$interface->stream->write(json_encode($responseData));
} else {
$interface->stream->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
{
}
}