2021-03-24 23:34:46 +08:00
|
|
|
<?php
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
declare(strict_types=1);
|
2021-03-24 23:34:46 +08:00
|
|
|
|
|
|
|
|
namespace ZM\Command;
|
|
|
|
|
|
2022-12-17 21:53:08 +08:00
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
2021-03-24 23:34:46 +08:00
|
|
|
|
2022-12-17 21:53:08 +08:00
|
|
|
#[AsCommand(name: 'check:config', description: '检查配置文件是否和框架当前版本有更新')]
|
2021-03-24 23:34:46 +08:00
|
|
|
class CheckConfigCommand extends Command
|
|
|
|
|
{
|
2022-12-19 20:22:47 +08:00
|
|
|
private bool $need_update = false;
|
2021-03-24 23:34:46 +08:00
|
|
|
|
2022-12-17 22:18:50 +08:00
|
|
|
protected function handle(): int
|
2022-03-15 18:05:33 +08:00
|
|
|
{
|
2022-12-18 18:33:51 +08:00
|
|
|
$current_cfg = SOURCE_ROOT_DIR . '/config/';
|
2023-02-10 16:03:21 +08:00
|
|
|
$remote_cfg = include FRAMEWORK_ROOT_DIR . '/config/global.php';
|
2022-03-15 18:05:33 +08:00
|
|
|
if (file_exists($current_cfg . 'global.php')) {
|
2022-12-17 22:18:50 +08:00
|
|
|
$this->check($remote_cfg, 'global.php');
|
2021-03-24 23:34:46 +08:00
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
if (file_exists($current_cfg . 'global.development.php')) {
|
2022-12-17 22:18:50 +08:00
|
|
|
$this->check($remote_cfg, 'global.development.php');
|
2021-03-24 23:34:46 +08:00
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
if (file_exists($current_cfg . 'global.staging.php')) {
|
2022-12-17 22:18:50 +08:00
|
|
|
$this->check($remote_cfg, 'global.staging.php');
|
2021-03-24 23:34:46 +08:00
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
if (file_exists($current_cfg . 'global.production.php')) {
|
2022-12-17 22:18:50 +08:00
|
|
|
$this->check($remote_cfg, 'global.production.php');
|
2021-03-24 23:34:46 +08:00
|
|
|
}
|
|
|
|
|
if ($this->need_update === true) {
|
2022-12-17 22:18:50 +08:00
|
|
|
$this->comment('有配置文件需要更新,详情见文档 `https://framework.zhamao.xin/update/config`');
|
2021-03-25 16:18:09 +08:00
|
|
|
} else {
|
2022-12-17 22:18:50 +08:00
|
|
|
$this->info('配置文件暂无更新!');
|
2021-03-24 23:34:46 +08:00
|
|
|
}
|
2021-03-25 16:18:09 +08:00
|
|
|
|
2022-12-17 22:18:50 +08:00
|
|
|
return self::SUCCESS;
|
2021-03-24 23:34:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-12-18 18:33:51 +08:00
|
|
|
private function check(mixed $remote, mixed $local)
|
2022-03-15 18:05:33 +08:00
|
|
|
{
|
2022-12-17 22:18:50 +08:00
|
|
|
$local_file = include WORKING_DIR . '/config/' . $local;
|
2021-07-09 01:38:30 +08:00
|
|
|
if ($local_file === true) {
|
2022-08-23 18:02:00 +08:00
|
|
|
$local_file = config('global');
|
2021-07-09 01:38:30 +08:00
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
foreach ($remote as $k => $v) {
|
2021-03-24 23:34:46 +08:00
|
|
|
if (!isset($local_file[$k])) {
|
2022-12-17 22:18:50 +08:00
|
|
|
$this->comment("配置文件 {$local} 需要更新!(当前配置文件缺少 `{$k}` 字段配置)");
|
2021-03-24 23:34:46 +08:00
|
|
|
$this->need_update = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|