改进Response类的send方法和getContent方法

This commit is contained in:
thinkphp
2016-06-13 16:54:07 +08:00
parent 4689c86e0a
commit 126bb348ca

View File

@@ -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);
} }
/** /**