mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-06 16:25:36 +08:00
refactor module command to phpstan-level-1
This commit is contained in:
@@ -4,57 +4,41 @@ declare(strict_types=1);
|
||||
|
||||
namespace ZM\Command\Module;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Exception\ZMException;
|
||||
use ZM\Utils\DataProvider;
|
||||
use ZM\Utils\Manager\ModuleManager;
|
||||
|
||||
class ModulePackCommand extends Command
|
||||
class ModulePackCommand extends ModuleCommand
|
||||
{
|
||||
// the name of the command (the part after "bin/console")
|
||||
protected static $defaultName = 'module:pack';
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->addArgument('module-name', InputArgument::REQUIRED);
|
||||
$this->setDescription('将配置好的模块构建一个phar包');
|
||||
$this->setHelp('此功能将会把炸毛框架的模块打包为".phar",供发布和执行。');
|
||||
$this->addOption('target', 'D', InputOption::VALUE_REQUIRED, 'Output Directory | 指定输出目录');
|
||||
// ...
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ZMException
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
ZMConfig::setDirectory(DataProvider::getSourceRootDir() . '/config');
|
||||
ZMConfig::setEnv($args['env'] ?? '');
|
||||
if (ZMConfig::get('global') === false) {
|
||||
exit(zm_internal_errcode('E00007') . 'Global config load failed: ' . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
|
||||
}
|
||||
|
||||
// 定义常量
|
||||
include_once DataProvider::getFrameworkRootDir() . '/src/ZM/global_defines.php';
|
||||
|
||||
Console::init(
|
||||
ZMConfig::get('global', 'info_level') ?? 2,
|
||||
null,
|
||||
$args['log-theme'] ?? 'default',
|
||||
($o = ZMConfig::get('console_color')) === false ? [] : $o
|
||||
);
|
||||
|
||||
$timezone = ZMConfig::get('global', 'timezone') ?? 'Asia/Shanghai';
|
||||
date_default_timezone_set($timezone);
|
||||
|
||||
parent::execute($input, $output);
|
||||
$list = ModuleManager::getConfiguredModules();
|
||||
if (!isset($list[$input->getArgument('module-name')])) {
|
||||
$output->writeln('<error>不存在模块 ' . $input->getArgument('module-name') . ' !</error>');
|
||||
return 1;
|
||||
}
|
||||
$result = ModuleManager::packModule($list[$input->getArgument('module-name')], $input->getOption('target'));
|
||||
$result = ModuleManager::packModule($list[$input->getArgument('module-name')], $input->getOption('target') ?? (DataProvider::getDataFolder() . '/output'));
|
||||
if ($result) {
|
||||
Console::success('打包完成!');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user