update to 2.0.0-b8 version

fix environment conflict and remove custom commands
This commit is contained in:
jerry
2020-12-20 18:49:03 +08:00
parent 42d9c97711
commit bc0bb9b6b0
4 changed files with 21 additions and 36 deletions

View File

@@ -106,11 +106,6 @@ $config['server_event_handler_class'] = [
\ZM\Event\ServerEventHandler::class, \ZM\Event\ServerEventHandler::class,
]; ];
/** 注册自定义指令的类 */
$config['command_register_class'] = [
//\Custom\Command\CustomCommand::class
];
/** 服务器启用的外部第三方和内部插件 */ /** 服务器启用的外部第三方和内部插件 */
$config['modules'] = [ $config['modules'] = [
'onebot' => [ 'onebot' => [

View File

@@ -7,7 +7,6 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use ZM\Config\ZMConfig;
use ZM\Framework; use ZM\Framework;
class RunServerCommand extends Command class RunServerCommand extends Command
@@ -42,7 +41,6 @@ class RunServerCommand extends Command
$output->writeln("<error> \"--env\" option only accept production, development, staging and [empty] ! </error>"); $output->writeln("<error> \"--env\" option only accept production, development, staging and [empty] ! </error>");
return Command::FAILURE; return Command::FAILURE;
} }
ZMConfig::setEnv($opt);
} }
// ... put here the code to run in your command // ... put here the code to run in your command
// this method must return an integer number with the "exit status code" // this method must return an integer number with the "exit status code"

View File

@@ -5,27 +5,22 @@ namespace ZM;
use Exception; use Exception;
use Symfony\Component\Console\Command\Command;
use TypeError;
use ZM\Command\InitCommand; use ZM\Command\InitCommand;
use ZM\Command\PureHttpCommand; use ZM\Command\PureHttpCommand;
use ZM\Command\RunServerCommand; use ZM\Command\RunServerCommand;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use ZM\Config\ZMConfig;
use ZM\Utils\DataProvider; use ZM\Utils\DataProvider;
class ConsoleApplication extends Application class ConsoleApplication extends Application
{ {
public function __construct(string $name = 'UNKNOWN') public function __construct(string $name = 'UNKNOWN') {
{
$version = json_decode(file_get_contents(__DIR__ . "/../../composer.json"), true)["version"] ?? "UNKNOWN"; $version = json_decode(file_get_contents(__DIR__ . "/../../composer.json"), true)["version"] ?? "UNKNOWN";
parent::__construct($name, $version); parent::__construct($name, $version);
} }
public function initEnv() public function initEnv() {
{
$this->selfCheck(); $this->selfCheck();
//if (LOAD_MODE === 0) $this->add(new BuildCommand()); //只有在git源码模式才能使用打包指令 //if (LOAD_MODE === 0) $this->add(new BuildCommand()); //只有在git源码模式才能使用打包指令
@@ -68,24 +63,18 @@ class ConsoleApplication extends Application
} }
} }
ZMConfig::setDirectory(DataProvider::getWorkingDir() . '/config'); $this->addCommands([
ZMConfig::setEnv($args["env"] ?? ""); new RunServerCommand(), //运行主服务的指令控制器
if (ZMConfig::get("global") === false) { new InitCommand(), //初始化用的用于项目初始化和phar初始化
echo ("Global config load failed: " . ZMConfig::$last_error."\nPlease init first!\n"); new PureHttpCommand() //纯HTTP服务器指令
$this->add(new InitCommand()); ]);
} else { /*
$this->addCommands([ $command_register = ZMConfig::get("global", "command_register_class") ?? [];
new RunServerCommand(), //运行主服务的指令控制器 foreach ($command_register as $v) {
new InitCommand(), //初始化用的用于项目初始化和phar初始化 $obj = new $v();
new PureHttpCommand() //纯HTTP服务器指令 if (!($obj instanceof Command)) throw new TypeError("Command register class must be extended by Symfony\\Component\\Console\\Command\\Command");
]); $this->add($obj);
$command_register = ZMConfig::get("global", "command_register_class") ?? []; }*/
foreach ($command_register as $v) {
$obj = new $v();
if (!($obj instanceof Command)) throw new TypeError("Command register class must be extended by Symfony\\Component\\Console\\Command\\Command");
$this->add($obj);
}
}
} }
/** /**
@@ -93,8 +82,7 @@ class ConsoleApplication extends Application
* @param OutputInterface|null $output * @param OutputInterface|null $output
* @return int * @return int
*/ */
public function run(InputInterface $input = null, OutputInterface $output = null) public function run(InputInterface $input = null, OutputInterface $output = null) {
{
try { try {
return parent::run($input, $output); return parent::run($input, $output);
} catch (Exception $e) { } catch (Exception $e) {
@@ -102,8 +90,7 @@ class ConsoleApplication extends Application
} }
} }
private function selfCheck() private function selfCheck() {
{
if (!extension_loaded("swoole")) die("Can not find swoole extension.\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/19"); if (!extension_loaded("swoole")) die("Can not find swoole extension.\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/19");
if (version_compare(SWOOLE_VERSION, "4.4.13") == -1) die("You must install swoole version >= 4.4.13 !"); if (version_compare(SWOOLE_VERSION, "4.4.13") == -1) die("You must install swoole version >= 4.4.13 !");
//if (!extension_loaded("gd")) die("Can not find gd extension.\n"); //if (!extension_loaded("gd")) die("Can not find gd extension.\n");

View File

@@ -48,6 +48,11 @@ class Framework
include_once "global_defines.php"; include_once "global_defines.php";
ZMAtomic::init(); ZMAtomic::init();
ZMConfig::setDirectory(DataProvider::getWorkingDir() . '/config');
ZMConfig::setEnv($args["env"] ?? "");
if (ZMConfig::get("global") === false) {
die ("Global config load failed: " . ZMConfig::$last_error . "\nPlease init first!\n");
}
try { try {
ManagerGM::init(ZMConfig::get("global", "swoole")["max_connection"] ?? 2048, 0.5, [ ManagerGM::init(ZMConfig::get("global", "swoole")["max_connection"] ?? 2048, 0.5, [
[ [