2023-04-15 23:29:27 +08:00
|
|
|
<?php
|
2023-04-16 01:24:30 +08:00
|
|
|
declare(strict_types=1);
|
2023-04-15 23:29:27 +08:00
|
|
|
|
|
|
|
|
namespace Kiri\Router;
|
|
|
|
|
|
2023-04-15 23:31:16 +08:00
|
|
|
use Exception;
|
2023-04-24 10:54:56 +08:00
|
|
|
use Kiri\Di\Interface\ResponseEmitterInterface;
|
2023-04-15 23:31:16 +08:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
|
|
|
|
|
|
2023-04-24 14:23:24 +08:00
|
|
|
class SwooleHttpResponseEmitter implements ResponseEmitterInterface
|
2023-04-15 23:29:27 +08:00
|
|
|
{
|
|
|
|
|
|
2023-04-15 23:31:16 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Response $proxy
|
|
|
|
|
* @param object $response
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function sender(ResponseInterface $proxy, object $response): void
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement sender() method.
|
|
|
|
|
$this->writeParams($proxy, $response);
|
|
|
|
|
|
2023-04-16 15:57:50 +08:00
|
|
|
$proxy->end($response);
|
2023-04-15 23:31:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Response $proxy
|
2023-04-19 10:51:08 +08:00
|
|
|
* @param object $response
|
2023-04-15 23:31:16 +08:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private function writeParams(ResponseInterface $proxy, object $response): void
|
|
|
|
|
{
|
|
|
|
|
$response->setStatusCode($proxy->getStatusCode());
|
2023-04-16 14:07:35 +08:00
|
|
|
foreach ($proxy->getHeaders() as $name => $header) {
|
2023-04-16 03:31:35 +08:00
|
|
|
$response->header($name, $header);
|
2023-04-15 23:31:16 +08:00
|
|
|
}
|
2023-04-16 14:07:35 +08:00
|
|
|
foreach ($proxy->getCookieParams() as $cookie) {
|
2023-04-15 23:31:16 +08:00
|
|
|
$response->setCookie(...$cookie);
|
|
|
|
|
}
|
|
|
|
|
$response->header('Server', 'swoole');
|
|
|
|
|
$response->header('Swoole-Version', swoole_version());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-04-15 23:29:27 +08:00
|
|
|
}
|