mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进Response类的send方法和getContent方法
This commit is contained in:
@@ -22,8 +22,6 @@ class Response
|
|||||||
protected $transform;
|
protected $transform;
|
||||||
// 原始数据
|
// 原始数据
|
||||||
protected $data;
|
protected $data;
|
||||||
// 输出数据
|
|
||||||
protected $content;
|
|
||||||
// 输出类型
|
// 输出类型
|
||||||
protected $type;
|
protected $type;
|
||||||
// 当前的contentType
|
// 当前的contentType
|
||||||
@@ -112,9 +110,7 @@ class Response
|
|||||||
defined('RESPONSE_TYPE') or define('RESPONSE_TYPE', $this->type);
|
defined('RESPONSE_TYPE') or define('RESPONSE_TYPE', $this->type);
|
||||||
|
|
||||||
// 处理输出数据
|
// 处理输出数据
|
||||||
$data = $this->getTransformData();
|
$data = $this->getContent();
|
||||||
// 输出数据赋值
|
|
||||||
$this->content = $data;
|
|
||||||
|
|
||||||
// 监听response_data
|
// 监听response_data
|
||||||
Hook::listen('response_data', $data, $this);
|
Hook::listen('response_data', $data, $this);
|
||||||
@@ -144,22 +140,6 @@ class Response
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理数据
|
|
||||||
* @access protected
|
|
||||||
* @param mixed $data 要处理的数据
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
protected function getTransformData()
|
|
||||||
{
|
|
||||||
if (is_callable($this->transform)) {
|
|
||||||
$data = call_user_func_array($this->transform, [$this->data]);
|
|
||||||
}else{
|
|
||||||
$data = $this->data;
|
|
||||||
}
|
|
||||||
return $this->output($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理数据
|
* 处理数据
|
||||||
* @access protected
|
* @access protected
|
||||||
@@ -346,7 +326,12 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
return $this->content;
|
if (is_callable($this->transform)) {
|
||||||
|
$data = call_user_func_array($this->transform, [$this->data]);
|
||||||
|
}else{
|
||||||
|
$data = $this->data;
|
||||||
|
}
|
||||||
|
return $this->output($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user