2021-03-24 23:34:46 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
|
|
$this->setDescription("检查配置文件是否和框架当前版本有更新");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
|
|
|
|
|
if (LOAD_MODE !== 1) {
|
|
|
|
|
|
$output->writeln("<error>仅限在Composer依赖模式中使用此命令!");
|
|
|
|
|
|
return Command::FAILURE;
|
|
|
|
|
|
}
|
2021-03-25 16:18:09 +08:00
|
|
|
|
$current_cfg = getcwd() . "/config/";
|
|
|
|
|
|
$remote_cfg = include_once WORKING_DIR . "/config/global.php";
|
2021-03-24 23:34:46 +08:00
|
|
|
|
if (file_exists($current_cfg . "global.php")) {
|
|
|
|
|
|
$this->check($remote_cfg, "global.php", $output);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (file_exists($current_cfg . "global.development.php")) {
|
|
|
|
|
|
$this->check($remote_cfg, "global.development.php", $output);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (file_exists($current_cfg . "global.staging.php")) {
|
|
|
|
|
|
$this->check($remote_cfg, "global.staging.php", $output);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (file_exists($current_cfg . "global.production.php")) {
|
|
|
|
|
|
$this->check($remote_cfg, "global.production.php", $output);
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($this->need_update === true) {
|
|
|
|
|
|
$output->writeln("<comment>有配置文件需要更新,详情见文档 https://framework.zhamao.xin/update/config.md</comment>");
|
2021-03-25 16:18:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
$output->writeln("<info>配置文件暂无更新!</info>");
|
2021-03-24 23:34:46 +08:00
|
|
|
|
}
|
2021-03-25 16:18:09 +08:00
|
|
|
|
|
2021-03-24 23:34:46 +08:00
|
|
|
|
return Command::SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-25 16:18:09 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @noinspection PhpIncludeInspection
|
|
|
|
|
|
*/
|
2021-03-24 23:34:46 +08:00
|
|
|
|
private function check($remote, $local, OutputInterface $out) {
|
2021-03-25 16:18:09 +08:00
|
|
|
|
$local_file = include_once getcwd() . "/config/".$local;
|
2021-03-24 23:34:46 +08:00
|
|
|
|
foreach($remote as $k => $v) {
|
2021-03-25 16:18:09 +08:00
|
|
|
|
$out->writeln("<comment>正在检查".$k."</comment>");
|
2021-03-24 23:34:46 +08:00
|
|
|
|
if (!isset($local_file[$k])) {
|
2021-03-25 16:18:09 +08:00
|
|
|
|
$out->writeln("<error>配置文件 ".$local . " 需要更新!(缺少 `$k` 字段配置)</error>");
|
2021-03-24 23:34:46 +08:00
|
|
|
|
$this->need_update = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|