update to v2.0.0-b4 version

change global.php config load time and logic
set context get server function available more time
delete unused comment and @CQAPISend
@CQCommand add start_with and end_with
set exceptions extended by ZMException
rename @SwooleSetup to @ZMSetup
fix quotes for global.php
fix LightCache empty presistence_path error
remove RemoteShell
This commit is contained in:
crazywhalecc
2020-12-10 16:37:04 +08:00
parent 944a9e849b
commit 1ffb30a471
21 changed files with 110 additions and 381 deletions

View File

@@ -18,18 +18,16 @@ use ZM\Utils\DataProvider;
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";
parent::__construct($name, $version);
}
public function initEnv() {
public function initEnv()
{
$this->selfCheck();
$this->addCommands([
new RunServerCommand(), //运行主服务的指令控制器
new InitCommand(), //初始化用的用于项目初始化和phar初始化
new PureHttpCommand()
]);
//if (LOAD_MODE === 0) $this->add(new BuildCommand()); //只有在git源码模式才能使用打包指令
if (LOAD_MODE === 0) define("WORKING_DIR", getcwd());
elseif (LOAD_MODE == 1) define("WORKING_DIR", realpath(__DIR__ . "/../../"));
@@ -47,20 +45,49 @@ class ConsoleApplication extends Application
* @noinspection RedundantSuppression
*/
require_once WORKING_DIR . "/vendor/autoload.php";
echo "* This is repository mode.\n";
$composer = json_decode(file_get_contents(DataProvider::getWorkingDir() . "/composer.json"), true);
if (!isset($composer["autoload"]["psr-4"]["Module\\"])) {
echo "框架源码模式需要在autoload文件中添加Module目录为自动加载是否添加[Y/n] ";
$r = strtolower(trim(fgets(STDIN)));
if ($r === "" || $r === "y") {
$composer["autoload"]["psr-4"]["Module\\"] = "src/Module";
$composer["autoload"]["psr-4"]["Custom\\"] = "src/Custom";
$r = file_put_contents(DataProvider::getWorkingDir() . "/composer.json", json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
if ($r !== false) {
echo "成功添加!请重新进行 composer update \n";
exit(1);
} else {
echo "添加失败!请按任意键继续!";
fgets(STDIN);
exit(1);
}
} else {
exit(1);
}
}
}
if (!is_dir(DataProvider::getWorkingDir() . '/src/')) {
die("Unable to find source directory.\nMaybe you need to run \"init\"?");
}
ZMConfig::setDirectory(DataProvider::getWorkingDir().'/config');
ZMConfig::setDirectory(DataProvider::getWorkingDir() . '/config');
ZMConfig::env($args["env"] ?? "");
if(ZMConfig::get("global") === false) die("Global config load failed: ".ZMConfig::$last_error);
$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);
if (ZMConfig::get("global") === false) {
echo ("Global config load failed: " . ZMConfig::$last_error."\nPlease init first!\n");
$this->add(new InitCommand());
} else {
$this->addCommands([
new RunServerCommand(), //运行主服务的指令控制器
new InitCommand(), //初始化用的用于项目初始化和phar初始化
new PureHttpCommand() //纯HTTP服务器指令
]);
$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);
}
}
}
@@ -69,7 +96,8 @@ class ConsoleApplication extends Application
* @param OutputInterface|null $output
* @return int
*/
public function run(InputInterface $input = null, OutputInterface $output = null) {
public function run(InputInterface $input = null, OutputInterface $output = null)
{
try {
return parent::run($input, $output);
} catch (Exception $e) {
@@ -77,12 +105,13 @@ class ConsoleApplication extends Application
}
}
private function selfCheck() {
if (!extension_loaded("swoole")) die("Can not find swoole extension.\n");
private function selfCheck()
{
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 (!extension_loaded("gd")) die("Can not find gd extension.\n");
if (!extension_loaded("sockets")) die("Can not find sockets extension.\n");
if (substr(PHP_VERSION, 0, 1) != "7") die("PHP >=7 required.\n");
//if (!extension_loaded("sockets")) die("Can not find sockets extension.\n");
if (substr(PHP_VERSION, 0, 1) < "7") die("PHP >=7 required.\n");
//if (!function_exists("curl_exec")) die("Can not find curl extension.\n");
//if (!class_exists("ZipArchive")) die("Can not find Zip extension.\n");
//if (!file_exists(CRASH_DIR . "last_error.log")) die("Can not find log file.\n");