This commit is contained in:
2021-08-24 18:24:46 +08:00
parent 575f4b8520
commit 24c93edf2b
110 changed files with 5 additions and 6 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace Server\Constrict;
use Exception;
use Http\Context\Formatter\FileFormatter;
use Kiri\Exception\NotFindClassException;
use ReflectionException;
use Server\ResponseInterface;
use Swoole\Server;
/**
*
*/
class ResponseEmitter implements Emitter
{
/**
* @param \Swoole\Http\Response|\Swoole\Http2\Response $response
* @param ResponseInterface $emitter
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
public function sender(mixed $response, ResponseInterface $emitter): void
{
$content = $emitter->configure($response)->getContent();
if ($content instanceof FileFormatter) {
di(DownloadEmitter::class)->sender($response, $emitter);
return;
}
$response->header('Content-Type', $emitter->getResponseFormat());
$response->end($content->getData());
}
}