add:优雅的返回 Json 数据
This commit is contained in:
parent
b07defb0e9
commit
3fb55deaaf
38
extend/catcher/middlewares/JsonResponseMiddleware.php
Normal file
38
extend/catcher/middlewares/JsonResponseMiddleware.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace catcher\middlewares;
|
||||||
|
|
||||||
|
use catcher\exceptions\FailedException;
|
||||||
|
use catcher\exceptions\PermissionForbiddenException;
|
||||||
|
use think\Middleware;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class JsonResponseMiddleware extends Middleware
|
||||||
|
{
|
||||||
|
public function handle(Request $request, \Closure $next)
|
||||||
|
{
|
||||||
|
$server = $request->server();
|
||||||
|
$server['HTTP_ACCEPT'] = 'application/json';
|
||||||
|
$request->withServer($server);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user