48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ywxapp<admin@ywxapp.cn>
|
|
// +----------------------------------------------------------------------
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace ywxapp\middleware;
|
|
|
|
use Closure;
|
|
use think\Request;
|
|
use think\Response;
|
|
use ywxapp\service\AddonHotReload;
|
|
|
|
/**
|
|
* 插件热重载中间件
|
|
*
|
|
* 在开发环境中自动检测插件文件变更并执行热重载
|
|
*/
|
|
class AddonHotReloadMiddleware
|
|
{
|
|
/**
|
|
* 处理请求
|
|
*
|
|
* @param Request $request
|
|
* @param Closure $next
|
|
* @return Response
|
|
*/
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
// 仅在开发环境启用
|
|
if (config('app.app_debug')) {
|
|
try {
|
|
// 启用自动热重载检测
|
|
AddonHotReload::enableAutoReload();
|
|
} catch (\Exception $e) {
|
|
// 静默处理错误,避免影响正常请求
|
|
\think\facade\Log::warning("插件热重载中间件执行失败:" . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
} |