router->Branch_search(\Server\Constrict\Request::create($request));
if (!($node instanceof Node)) {
throw new RequestException('
HTTP 404 Not Found
Powered by Swoole', 404);
}
if (!(($responseData = $node->dispatch()) instanceof ResponseInterface)) {
$responseData = $this->transferToResponse($responseData);
}
} catch (Error | \Throwable $exception) {
$responseData = $this->exceptionHandler->emit($exception, $this->response);
} finally {
$this->responseEmitter->sender($response, $responseData);
$this->eventDispatch->dispatch(new OnAfterRequest());
}
}
/**
* @param $responseData
* @return \Server\ResponseInterface
*/
private function transferToResponse($responseData): ResponseInterface
{
$this->response->withStatus(200);
if (is_object($responseData)) {
if (!($responseData instanceof ToArray)) {
$responseData = get_object_vars($responseData);
} else {
$responseData = $responseData->toArray();
}
}
if (is_array($responseData)) {
return $this->response->withBody(new Stream(json_encode($responseData, JSON_UNESCAPED_UNICODE)))
->withContentType(\Server\Message\Response::CONTENT_TYPE_JSON);
}
return $this->response->withBody(new Stream((string)$responseData));
}
/**
* @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
{
}
}