mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-09 08:02:48 +08:00
改进Response类 支持手动设置contentType
This commit is contained in:
@@ -19,7 +19,6 @@ use think\response\Xml as XmlResponse;
|
|||||||
|
|
||||||
class Response
|
class Response
|
||||||
{
|
{
|
||||||
|
|
||||||
// 原始数据
|
// 原始数据
|
||||||
protected $data;
|
protected $data;
|
||||||
|
|
||||||
@@ -50,12 +49,12 @@ class Response
|
|||||||
public function __construct($data = '', $code = 200, array $header = [], $options = [])
|
public function __construct($data = '', $code = 200, array $header = [], $options = [])
|
||||||
{
|
{
|
||||||
$this->data($data);
|
$this->data($data);
|
||||||
$this->header = $header;
|
|
||||||
$this->code = $code;
|
|
||||||
if (!empty($options)) {
|
if (!empty($options)) {
|
||||||
$this->options = array_merge($this->options, $options);
|
$this->options = array_merge($this->options, $options);
|
||||||
}
|
}
|
||||||
$this->contentType($this->contentType, $this->charset);
|
$this->contentType($this->contentType, $this->charset);
|
||||||
|
$this->header = $header;
|
||||||
|
$this->code = $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,9 +196,9 @@ class Response
|
|||||||
public function content($content)
|
public function content($content)
|
||||||
{
|
{
|
||||||
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
||||||
$content,
|
$content,
|
||||||
'__toString',
|
'__toString',
|
||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
||||||
}
|
}
|
||||||
@@ -309,9 +308,9 @@ class Response
|
|||||||
$content = $this->output($this->data);
|
$content = $this->output($this->data);
|
||||||
|
|
||||||
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
||||||
$content,
|
$content,
|
||||||
'__toString',
|
'__toString',
|
||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user