2020-08-31 10:11:06 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
declare(strict_types=1);
|
2020-08-31 10:11:06 +08:00
|
|
|
|
|
|
|
|
|
|
namespace ZM;
|
|
|
|
|
|
|
|
|
|
|
|
use Exception;
|
2021-06-16 00:17:30 +08:00
|
|
|
|
use Phar;
|
2022-03-15 18:05:33 +08:00
|
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2021-06-16 00:17:30 +08:00
|
|
|
|
use ZM\Command\BuildCommand;
|
2021-03-24 23:34:46 +08:00
|
|
|
|
use ZM\Command\CheckConfigCommand;
|
2021-07-04 15:45:30 +08:00
|
|
|
|
use ZM\Command\Generate\SystemdGenerateCommand;
|
2020-08-31 10:11:06 +08:00
|
|
|
|
use ZM\Command\InitCommand;
|
2021-11-16 15:41:01 +08:00
|
|
|
|
use ZM\Command\Server\ServerReloadCommand;
|
2022-05-14 23:40:22 +08:00
|
|
|
|
use ZM\Command\Server\ServerStartCommand;
|
2021-11-16 15:41:01 +08:00
|
|
|
|
use ZM\Command\Server\ServerStatusCommand;
|
|
|
|
|
|
use ZM\Command\Server\ServerStopCommand;
|
2021-07-04 15:45:30 +08:00
|
|
|
|
use ZM\Exception\InitException;
|
2020-08-31 10:11:06 +08:00
|
|
|
|
|
2022-08-01 16:31:54 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 命令行启动的入口文件,用于初始化环境变量,并启动命令行应用
|
|
|
|
|
|
*
|
|
|
|
|
|
* 这里启动的不是框架,而是框架相关的命令行环境
|
|
|
|
|
|
*/
|
2020-08-31 10:11:06 +08:00
|
|
|
|
class ConsoleApplication extends Application
|
|
|
|
|
|
{
|
2022-03-15 18:05:33 +08:00
|
|
|
|
private static $obj;
|
2021-07-04 15:45:30 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @throws InitException
|
|
|
|
|
|
*/
|
2022-08-01 16:31:54 +08:00
|
|
|
|
public function __construct(string $name = 'zhamao-framework')
|
2022-03-15 18:05:33 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (self::$obj !== null) {
|
|
|
|
|
|
throw new InitException(zm_internal_errcode('E00069') . 'Initializing another Application is not allowed!');
|
|
|
|
|
|
}
|
2022-08-01 16:31:54 +08:00
|
|
|
|
// 如果已经有定义了全局的 WORKING_DIR,那么就报错
|
|
|
|
|
|
// if (defined('WORKING_DIR')) {
|
|
|
|
|
|
// throw new InitException();
|
|
|
|
|
|
// }
|
2020-12-10 16:37:04 +08:00
|
|
|
|
|
2022-08-01 16:31:54 +08:00
|
|
|
|
// 启动前检查炸毛运行情况
|
|
|
|
|
|
// _zm_env_check();
|
2022-03-13 22:50:01 +08:00
|
|
|
|
|
2022-08-01 16:31:54 +08:00
|
|
|
|
// 初始化命令
|
|
|
|
|
|
$this->add(new ServerStatusCommand()); // server运行状态
|
|
|
|
|
|
$this->add(new ServerReloadCommand()); // server重载
|
|
|
|
|
|
$this->add(new ServerStopCommand()); // server停止
|
|
|
|
|
|
$this->add(new ServerStartCommand()); // 运行主服务的指令控制器
|
|
|
|
|
|
$this->add(new SystemdGenerateCommand()); // 生成systemd文件
|
|
|
|
|
|
if (LOAD_MODE === 1) { // 如果是 Composer 模式加载的,那么可以输入 check:config 命令,检查配置文件是否需要更新
|
2021-03-24 23:34:46 +08:00
|
|
|
|
$this->add(new CheckConfigCommand());
|
|
|
|
|
|
}
|
2022-08-01 16:31:54 +08:00
|
|
|
|
if (Phar::running() === '') { // 不是 Phar 模式的话,可以执行打包解包初始化命令
|
|
|
|
|
|
$this->add(new BuildCommand()); // 用于将整个应用打包为一个可执行的 phar
|
|
|
|
|
|
$this->add(new InitCommand()); // 用于在 Composer 模式启动下,初始化脚手架文件
|
|
|
|
|
|
// $this->add(new PluginPackCommand()); // 用于打包一个子模块为 phar 并进行分发
|
|
|
|
|
|
// $this->add(new PluginListCommand()); // 用于列出已配置的子模块列表(存在 zm.json 文件的目录)
|
|
|
|
|
|
// $this->add(new PluginUnpackCommand()); // 用于将打包好的 phar 模块解包到 src 目录中
|
2021-06-16 00:17:30 +08:00
|
|
|
|
}
|
2022-08-01 16:31:54 +08:00
|
|
|
|
|
|
|
|
|
|
self::$obj = $this; // 用于标记已经初始化完成
|
|
|
|
|
|
parent::__construct($name, ZM_VERSION);
|
2020-08-31 10:11:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-01 16:31:54 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
|
public function run(InputInterface $input = null, OutputInterface $output = null): int
|
|
|
|
|
|
{
|
2020-08-31 10:11:06 +08:00
|
|
|
|
try {
|
|
|
|
|
|
return parent::run($input, $output);
|
|
|
|
|
|
} catch (Exception $e) {
|
2022-03-15 18:05:33 +08:00
|
|
|
|
echo zm_internal_errcode('E00005') . "{$e->getMessage()} at {$e->getFile()}({$e->getLine()})" . PHP_EOL;
|
|
|
|
|
|
exit(1);
|
2020-08-31 10:11:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|