This commit is contained in:
molong
2022-05-12 18:12:20 +08:00
parent c31729ec7e
commit fe38e19924
284 changed files with 33456 additions and 11 deletions

40
app/middleware/Api.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\middleware;
class Api{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next){
$response = $next($request);
if (is_array($response->getData())) {
$this->data = array_merge($this->data, $response->getData());
} else {
$this->data = $response->getData();
}
if ($request->isAjax()) {
return json($this->data);
} else {
if (\is_string($this->data) && $this->data != '') {
return $response;
} else {
return json($this->data);
}
}
}
}