dnsmgr/app/middleware/LoadConfig.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2024-04-03 20:51:10 +08:00
<?php
declare (strict_types = 1);
namespace app\middleware;
2024-04-18 19:35:14 +08:00
use Exception;
2024-04-03 20:51:10 +08:00
use think\facade\Db;
use think\facade\Config;
class LoadConfig
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
if (!file_exists(app()->getRootPath().'.env')){
if(strpos(request()->url(),'/install')===false){
return redirect((string)url('/install'))->header([
'Cache-Control' => 'no-store, no-cache, must-revalidate',
'Pragma' => 'no-cache',
]);
}else{
return $next($request);
}
}
2024-04-18 19:35:14 +08:00
try{
$res = Db::name('config')->cache('configs',0)->column('value','key');
Config::set($res, 'sys');
}catch(Exception $e){
if(!strpos($e->getMessage(), 'doesn\'t exist')){
throw $e;
}
}
2024-04-03 20:51:10 +08:00
$request->isApi = false;
return $next($request)->header([
'Cache-Control' => 'no-store, no-cache, must-revalidate',
'Pragma' => 'no-cache',
]);
}
}