Files
zhamao-framework/src/ZM/Command/Module/ModuleListCommand.php

80 lines
3.2 KiB
PHP
Raw Normal View History

2021-06-16 00:17:30 +08:00
<?php
namespace ZM\Command\Module;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use ZM\Config\ZMConfig;
use ZM\Console\Console;
use ZM\Utils\DataProvider;
use ZM\Utils\Manager\ModuleManager;
class ModuleListCommand extends Command
{
// the name of the command (the part after "bin/console")
protected static $defaultName = 'module:list';
protected function configure() {
2021-09-01 14:14:00 +08:00
$this->setDescription("查看所有模块信息");
$this->setHelp("此功能将会把炸毛框架的模块列举出来。");
2021-07-09 12:59:07 +08:00
// ...
}
protected function execute(InputInterface $input, OutputInterface $output): int {
2021-06-16 00:17:30 +08:00
ZMConfig::setDirectory(DataProvider::getSourceRootDir() . '/config');
ZMConfig::setEnv($args["env"] ?? "");
if (ZMConfig::get("global") === false) {
2021-07-04 15:45:30 +08:00
die (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");
2021-06-16 00:17:30 +08:00
}
//定义常量
2021-09-01 14:14:00 +08:00
/** @noinspection PhpIncludeInspection */
2021-06-16 00:17:30 +08:00
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);
$list = ModuleManager::getConfiguredModules();
foreach ($list as $v) {
echo "[" . Console::setColor($v["name"], "green") . "]" . PHP_EOL;
2021-09-01 14:14:00 +08:00
$out_list = ["类型" => "源码(source)"];
2021-06-16 00:17:30 +08:00
if (isset($v["version"])) $out_list["版本"] = $v["version"];
if (isset($v["description"])) $out_list["描述"] = $v["description"];
$out_list["目录"] = str_replace(DataProvider::getSourceRootDir() . "/", "", $v["module-path"]);
$this->printList($out_list);
}
2021-07-04 15:45:30 +08:00
if ($list === []) {
echo Console::setColor("没有发现已编写打包配置文件zm.json的模块", "yellow") . PHP_EOL;
}
2021-06-16 00:17:30 +08:00
$list = ModuleManager::getPackedModules();
foreach ($list as $v) {
echo "[" . Console::setColor($v["name"], "gold") . "]" . PHP_EOL;
2021-09-01 14:14:00 +08:00
$out_list = ["类型" => "模块包(phar)"];
2021-06-16 00:17:30 +08:00
if (isset($v["module-config"]["version"])) $out_list["版本"] = $v["module-config"]["version"];
if (isset($v["module-config"]["description"])) $out_list["描述"] = $v["module-config"]["description"];
$out_list["位置"] = str_replace(DataProvider::getSourceRootDir() . "/", "", $v["phar-path"]);
$this->printList($out_list);
}
if ($list === []) {
2021-07-04 15:45:30 +08:00
echo Console::setColor("没有发现已打包且装载的模块!", "yellow") . PHP_EOL;
2021-06-16 00:17:30 +08:00
}
return 0;
}
private function printList($list) {
foreach ($list as $k => $v) {
echo "\t" . $k . ": " . Console::setColor($v, "yellow") . PHP_EOL;
}
}
}