This commit is contained in:
2021-08-12 15:07:12 +08:00
parent 6ea406251c
commit 0d6176e4e2
13 changed files with 141 additions and 302 deletions
+17 -3
View File
@@ -46,6 +46,8 @@ class Response extends HttpService implements ResponseInterface
private mixed $endData;
private array $_clientInfo = [];
const FORMAT_MAPS = [
self::JSON => JsonFormatter::class,
self::XML => XmlFormatter::class,
@@ -69,11 +71,23 @@ class Response extends HttpService implements ResponseInterface
}
/**
* @param array $clientInfo
*/
public function setClientInfo(array $clientInfo)
{
$this->_clientInfo = $clientInfo;
}
/**
* @return mixed
*/
public function getClientInfo(): mixed
{
if (!empty($this->_clientInfo)) {
return $this->_clientInfo;
}
$server = ServerManager::getContext()->getServer();
return $server->getClientInfo($this->clientId, $this->reactorId);
}
@@ -152,17 +166,17 @@ class Response extends HttpService implements ResponseInterface
* @param bool $isChunk
* @param int $offset
* @param int $limit
* @return $this|Response
* @return FileResponse
* @throws Exception
*/
public function sendFile(string $path, bool $isChunk = false, int $offset = 0, int $limit = 10240): static
public function sendFile(string $path, bool $isChunk = false, int $offset = 0, int $limit = 10240): FileResponse
{
$this->format = self::FILE;
if (!file_exists($path)) {
throw new Exception('File `' . $path . '` not exists.');
}
$this->endData = ['path' => $path, 'isChunk' => $isChunk, 'limit' => $limit, 'offset' => $offset];
return $this;
return new FileResponse($this);
}