Files
kiri-core/http-server/Constrict/TcpEmitter.php
T

32 lines
572 B
PHP
Raw Normal View History

2021-08-12 15:07:12 +08:00
<?php
namespace Server\Constrict;
2021-09-09 17:17:44 +08:00
use Exception;
2021-09-20 02:58:23 +08:00
use Http\Handler\Formatter\FileFormatter;
2021-08-12 15:07:12 +08:00
use Swoole\Server;
/**
*
*/
class TcpEmitter implements Emitter
{
/**
* @param Server $response
* @param ResponseInterface $emitter
2021-09-09 17:17:44 +08:00
* @throws Exception
2021-08-12 15:07:12 +08:00
*/
2021-08-12 15:08:46 +08:00
public function sender(mixed $response, ResponseInterface $emitter): void
2021-08-12 15:07:12 +08:00
{
2021-09-09 17:17:44 +08:00
$formatter = $emitter->stream->getContents();
2021-08-12 15:07:12 +08:00
if ($formatter instanceof FileFormatter) {
2021-09-09 17:17:44 +08:00
$response->sendfile($emitter->getClientId(), $formatter);
2021-08-12 15:07:12 +08:00
} else {
2021-09-09 17:17:44 +08:00
$response->send($emitter->getClientId(), $formatter);
2021-08-12 15:07:12 +08:00
}
}
}