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

33 lines
612 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-08-17 16:52:50 +08:00
use Http\Context\Formatter\FileFormatter;
2021-09-10 10:45:24 +08:00
use Server\Constrict\ResponseInterface;
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
}
}
}