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

35 lines
720 B
PHP
Raw Normal View History

2021-08-12 15:07:12 +08:00
<?php
namespace Server\Constrict;
2021-08-17 16:52:50 +08:00
use Http\Context\Formatter\FileFormatter;
2021-08-12 15:07:12 +08:00
use Kiri\Exception\NotFindClassException;
2021-08-28 01:25:24 +08:00
use Psr\Http\Message\ResponseInterface;
2021-08-12 15:07:12 +08:00
use Swoole\Server;
/**
*
*/
class TcpEmitter implements Emitter
{
/**
* @param Server $response
* @param ResponseInterface $emitter
* @throws NotFindClassException
* @throws \ReflectionException
* @throws \Exception
*/
2021-08-12 15:08:46 +08:00
public function sender(mixed $response, ResponseInterface $emitter): void
2021-08-12 15:07:12 +08:00
{
$formatter = $emitter->getContent();
if ($formatter instanceof FileFormatter) {
$response->sendfile($emitter->getClientId(), $formatter->getData());
} else {
$response->send($emitter->getClientId(), $formatter->getData());
}
}
}