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;
|
|
|
|
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
|
|
class CheckConfigCommand extends Command
|
|
|
|
|
|
{
|
2021-03-25 16:18:09 +08:00
|
|
|
|
protected static $defaultName = 'check:config';
|
2021-03-24 23:34:46 +08:00
|
|
|
|
|
|
|
|
|
|
private $need_update = false;
|
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
protected function configure()
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->setDescription('检查配置文件是否和框架当前版本有更新');
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
|
|
{
|
2021-03-24 23:34:46 +08:00
|
|
|
|
if (LOAD_MODE !== 1) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$output->writeln('<error>仅限在Composer依赖模式中使用此命令!</error>');
|
2021-04-06 01:19:56 +08:00
|
|
|
|
return 1;
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$current_cfg = getcwd() . '/config/';
|
2022-08-01 16:31:54 +08:00
|
|
|
|
$remote_cfg = include_once FRAMEWORK_ROOT_DIR . '/config/global_old.php';
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (file_exists($current_cfg . 'global.php')) {
|
|
|
|
|
|
$this->check($remote_cfg, 'global.php', $output);
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (file_exists($current_cfg . 'global.development.php')) {
|
|
|
|
|
|
$this->check($remote_cfg, 'global.development.php', $output);
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (file_exists($current_cfg . 'global.staging.php')) {
|
|
|
|
|
|
$this->check($remote_cfg, 'global.staging.php', $output);
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if (file_exists($current_cfg . 'global.production.php')) {
|
|
|
|
|
|
$this->check($remote_cfg, 'global.production.php', $output);
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
if ($this->need_update === true) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$output->writeln('<comment>有配置文件需要更新,详情见文档 `https://framework.zhamao.xin/update/config`</comment>');
|
2021-03-25 16:18:09 +08:00
|
|
|
|
} else {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
$output->writeln('<info>配置文件暂无更新!</info>');
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
2021-03-25 16:18:09 +08:00
|
|
|
|
|
2021-04-06 01:19:56 +08:00
|
|
|
|
return 0;
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-25 16:18:09 +08:00
|
|
|
|
/**
|
2022-03-15 18:05:33 +08:00
|
|
|
|
* @param mixed $remote
|
|
|
|
|
|
* @param mixed $local
|
2021-03-25 16:18:09 +08:00
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
|
private function check($remote, $local, OutputInterface $out)
|
|
|
|
|
|
{
|
|
|
|
|
|
$local_file = include_once 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-03-15 18:05:33 +08:00
|
|
|
|
$out->writeln('<comment>配置文件 ' . $local . " 需要更新!(当前配置文件缺少 `{$k}` 字段配置)</comment>");
|
2021-03-24 23:34:46 +08:00
|
|
|
|
$this->need_update = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|