Files
kiri-core/HttpServer/Http/Formatter/HtmlFormatter.php
T

61 lines
888 B
PHP
Raw Normal View History

2020-08-31 01:27:08 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/8 0008
* Time: 17:51
*/
namespace HttpServer\Http\Formatter;
2020-08-31 12:38:32 +08:00
use Snowflake\Core\JSON;
2020-08-31 01:27:08 +08:00
use HttpServer\Application;
use Swoole\Http\Response;
use HttpServer\IInterface\IFormatter;
/**
* Class HtmlFormatter
2020-08-31 12:38:32 +08:00
* @package Snowflake\Snowflake\Http\Formatter
2020-08-31 01:27:08 +08:00
*/
class HtmlFormatter extends Application implements IFormatter
{
public $data;
/** @var Response */
2020-10-29 11:10:26 +08:00
public Response $status;
2020-08-31 01:27:08 +08:00
2020-10-29 11:10:26 +08:00
public array $header = [];
2020-08-31 01:27:08 +08:00
/**
* @param $data
* @return $this
* @throws \Exception
*/
public function send($data)
{
if (!is_string($data)) {
$data = JSON::encode($data);
}
$this->data = $data;
return $this;
}
/**
* @return mixed
*/
public function getData()
{
$data = $this->data;
$this->clear();
return $data;
}
public function clear()
{
2020-09-16 10:37:47 +08:00
$this->data = null;
2020-08-31 01:27:08 +08:00
unset($this->data);
}
}