mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
改进App类的run方法的返回值 改进Response类
This commit is contained in:
@@ -128,11 +128,13 @@ class App
|
|||||||
// 输出数据到客户端
|
// 输出数据到客户端
|
||||||
if ($data instanceof Response) {
|
if ($data instanceof Response) {
|
||||||
return $data;
|
return $data;
|
||||||
} else {
|
} elseif(!is_null($data)) {
|
||||||
// 默认自动识别响应输出类型
|
// 默认自动识别响应输出类型
|
||||||
$isAjax = $request->isAjax();
|
$isAjax = $request->isAjax();
|
||||||
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
||||||
return Response::create( is_null($data) ? '' : $data, $type);
|
return Response::create($data, $type);
|
||||||
|
} else {
|
||||||
|
return Response::create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,15 +51,12 @@ class Response
|
|||||||
public function __construct($data = [], $type = '', $options = [])
|
public function __construct($data = [], $type = '', $options = [])
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
if (empty($type)) {
|
$this->type = empty($type) ? 'null' : strtolower($type);
|
||||||
$isAjax = Request::instance()->isAjax();
|
|
||||||
$type = $isAjax ? 'json' : 'html';
|
|
||||||
}
|
|
||||||
$this->type = strtolower($type);
|
|
||||||
|
|
||||||
if (isset($this->contentTypes[$this->type])) {
|
if (isset($this->contentTypes[$this->type])) {
|
||||||
$this->contentType($this->contentTypes[$this->type]);
|
$this->contentType($this->contentTypes[$this->type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($options)) {
|
if (!empty($options)) {
|
||||||
$this->options = array_merge($this->options, $options);
|
$this->options = array_merge($this->options, $options);
|
||||||
}
|
}
|
||||||
@@ -77,11 +74,7 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public static function create($data = [], $type = '', $options = [])
|
public static function create($data = [], $type = '', $options = [])
|
||||||
{
|
{
|
||||||
if (empty($type)) {
|
$type = empty($type) ? 'null' : strtolower($type);
|
||||||
$isAjax = Request::instance()->isAjax();
|
|
||||||
$type = $isAjax ? 'json' : 'html';
|
|
||||||
}
|
|
||||||
$type = strtolower($type);
|
|
||||||
|
|
||||||
if (!isset(self::$instance[$type])) {
|
if (!isset(self::$instance[$type])) {
|
||||||
$class = (isset($options['namespace']) ? $options['namespace'] : '\\think\\response\\') . ucfirst($type);
|
$class = (isset($options['namespace']) ? $options['namespace'] : '\\think\\response\\') . ucfirst($type);
|
||||||
|
|||||||
Reference in New Issue
Block a user