mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
update to 2.2.8 version
update motd message
This commit is contained in:
parent
957c69bd1e
commit
4ff75cf199
12
bin/start
12
bin/start
@ -1,14 +1,6 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php /** @noinspection PhpIncludeInspection */
|
||||||
|
|
||||||
if (!is_dir(__DIR__ . '/../vendor')) {
|
require_once ((!is_dir(__DIR__ . '/../vendor')) ? getcwd() : (__DIR__ . "/..")) . "/vendor/autoload.php";
|
||||||
define("LOAD_MODE", 1); //composer项目模式
|
|
||||||
define("LOAD_MODE_COMPOSER_PATH", getcwd());
|
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
require_once LOAD_MODE_COMPOSER_PATH . "/vendor/autoload.php";
|
|
||||||
} else {
|
|
||||||
define("LOAD_MODE", 0); //源码模式
|
|
||||||
require_once __DIR__ . "/../vendor/autoload.php";
|
|
||||||
}
|
|
||||||
|
|
||||||
(new ZM\ConsoleApplication("zhamao-framework"))->initEnv()->run();
|
(new ZM\ConsoleApplication("zhamao-framework"))->initEnv()->run();
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
"description": "High performance QQ robot and web server development framework",
|
"description": "High performance QQ robot and web server development framework",
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"version": "2.2.7",
|
"version": "2.2.8",
|
||||||
"extra": {
|
"extra": {
|
||||||
"exclude_annotate": [
|
"exclude_annotate": [
|
||||||
"src/ZM"
|
"src/ZM"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
______
|
______
|
||||||
|__ / |__ __ _ _ __ ___ __ _ ___
|
|__ / |__ __ _ _ __ ___ __ _ ___
|
||||||
/ /| '_ \ / _` | '_ ` _ \ / _` |/ _ \
|
/ /| '_ \ / _` | '_ ` _ \ / _` |/ _ \
|
||||||
/ /_| | | | (_| | | | | | | (_| | (_) |
|
/ /_| | | | (_| | | | | | | (_| | (_) |
|
||||||
/____|_| |_|\__,_|_| |_| |_|\__,_|\___/
|
/____|_| |_|\__,_|_| |_| |_|\__,_|\___/
|
||||||
|
|
||||||
|
|||||||
@ -1 +1,3 @@
|
|||||||
# FAQ
|
# FAQ
|
||||||
|
|
||||||
|
这里会写一些常见的疑难解答。
|
||||||
@ -1,5 +1,11 @@
|
|||||||
# 更新日志(v2 版本)
|
# 更新日志(v2 版本)
|
||||||
|
|
||||||
|
## v2.2.8
|
||||||
|
|
||||||
|
> 更新时间:2021.3.2
|
||||||
|
|
||||||
|
- 更新:MOTD 显示的方式,更加直观和炫酷
|
||||||
|
|
||||||
## v2.2.7
|
## v2.2.7
|
||||||
|
|
||||||
> 更新时间:2021.2.27
|
> 更新时间:2021.2.27
|
||||||
@ -7,7 +13,6 @@
|
|||||||
- 修复:2.2.6 版本下 `reply()` 方法在群里调用会 at 成员的 bug
|
- 修复:2.2.6 版本下 `reply()` 方法在群里调用会 at 成员的 bug
|
||||||
- 修复:空 `access_token` 的情况下会无法连入的 bug
|
- 修复:空 `access_token` 的情况下会无法连入的 bug
|
||||||
- 修复:使用 Closure 闭包函数自行编写逻辑的判断返回 false 无法阻断连接的 bug
|
- 修复:使用 Closure 闭包函数自行编写逻辑的判断返回 false 无法阻断连接的 bug
|
||||||
-
|
|
||||||
|
|
||||||
## v2.2.6
|
## v2.2.6
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,6 @@ class RunServerCommand extends Command
|
|||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (LOAD_MODE == 0) echo "* This is repository mode.\n";
|
|
||||||
(new Framework($input->getOptions()))->start();
|
(new Framework($input->getOptions()))->start();
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,23 +26,21 @@ class ConsoleApplication extends Application
|
|||||||
public function initEnv() {
|
public function initEnv() {
|
||||||
$this->selfCheck();
|
$this->selfCheck();
|
||||||
|
|
||||||
|
if (!is_dir(__DIR__ . '/../../vendor')) {
|
||||||
|
define("LOAD_MODE", 1); // composer项目模式
|
||||||
|
define("LOAD_MODE_COMPOSER_PATH", getcwd());
|
||||||
|
} else {
|
||||||
|
define("LOAD_MODE", 0); // 源码模式
|
||||||
|
}
|
||||||
|
|
||||||
//if (LOAD_MODE === 0) $this->add(new BuildCommand()); //只有在git源码模式才能使用打包指令
|
//if (LOAD_MODE === 0) $this->add(new BuildCommand()); //只有在git源码模式才能使用打包指令
|
||||||
if (LOAD_MODE === 0) define("WORKING_DIR", getcwd());
|
if (LOAD_MODE === 0) define("WORKING_DIR", getcwd());
|
||||||
elseif (LOAD_MODE == 1) define("WORKING_DIR", realpath(__DIR__ . "/../../"));
|
elseif (LOAD_MODE == 1) define("WORKING_DIR", realpath(__DIR__ . "/../../"));
|
||||||
elseif (LOAD_MODE == 2) echo "Phar mode: " . WORKING_DIR . PHP_EOL;
|
|
||||||
if (file_exists(DataProvider::getWorkingDir() . "/vendor/autoload.php")) {
|
if (file_exists(DataProvider::getWorkingDir() . "/vendor/autoload.php")) {
|
||||||
/** @noinspection PhpIncludeInspection */
|
/** @noinspection PhpIncludeInspection */
|
||||||
require_once DataProvider::getWorkingDir() . "/vendor/autoload.php";
|
require_once DataProvider::getWorkingDir() . "/vendor/autoload.php";
|
||||||
}
|
}
|
||||||
if (LOAD_MODE == 2) {
|
if (LOAD_MODE == 0) {
|
||||||
// Phar 模式,2.0 不提供哦
|
|
||||||
//require_once FRAMEWORK_DIR . "/vendor/autoload.php";
|
|
||||||
spl_autoload_register('phar_classloader');
|
|
||||||
} elseif (LOAD_MODE == 0) {
|
|
||||||
/** @noinspection PhpIncludeInspection
|
|
||||||
* @noinspection RedundantSuppression
|
|
||||||
*/
|
|
||||||
require_once WORKING_DIR . "/vendor/autoload.php";
|
|
||||||
$composer = json_decode(file_get_contents(DataProvider::getWorkingDir() . "/composer.json"), true);
|
$composer = json_decode(file_get_contents(DataProvider::getWorkingDir() . "/composer.json"), true);
|
||||||
if (!isset($composer["autoload"]["psr-4"]["Module\\"])) {
|
if (!isset($composer["autoload"]["psr-4"]["Module\\"])) {
|
||||||
echo "框架源码模式需要在autoload文件中添加Module目录为自动加载,是否添加?[Y/n] ";
|
echo "框架源码模式需要在autoload文件中添加Module目录为自动加载,是否添加?[Y/n] ";
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use Exception;
|
|||||||
use ZM\Annotation\Swoole\OnSetup;
|
use ZM\Annotation\Swoole\OnSetup;
|
||||||
use ZM\Config\ZMConfig;
|
use ZM\Config\ZMConfig;
|
||||||
use ZM\ConnectionManager\ManagerGM;
|
use ZM\ConnectionManager\ManagerGM;
|
||||||
|
use ZM\Console\TermColor;
|
||||||
use ZM\Event\ServerEventHandler;
|
use ZM\Event\ServerEventHandler;
|
||||||
use ZM\Store\LightCache;
|
use ZM\Store\LightCache;
|
||||||
use ZM\Store\LightCacheInside;
|
use ZM\Store\LightCacheInside;
|
||||||
@ -87,35 +88,37 @@ class Framework
|
|||||||
|
|
||||||
$this->parseCliArgs(self::$argv);
|
$this->parseCliArgs(self::$argv);
|
||||||
|
|
||||||
$out = [
|
|
||||||
"host" => ZMConfig::get("global", "host"),
|
|
||||||
"port" => ZMConfig::get("global", "port"),
|
|
||||||
"log_level" => Console::getLevel(),
|
|
||||||
"version" => ZM_VERSION,
|
|
||||||
"config" => $args["env"] === null ? 'global.php' : $args["env"]
|
|
||||||
];
|
|
||||||
if (APP_VERSION !== "unknown") $out["app_version"] = APP_VERSION;
|
|
||||||
if (isset(ZMConfig::get("global", "swoole")["task_worker_num"])) {
|
|
||||||
$out["task_worker_num"] = ZMConfig::get("global", "swoole")["task_worker_num"];
|
|
||||||
}
|
|
||||||
if (($num = ZMConfig::get("global", "swoole")["worker_num"] ?? swoole_cpu_num()) != 1) {
|
|
||||||
$out["worker_num"] = $num;
|
|
||||||
}
|
|
||||||
$out["working_dir"] = DataProvider::getWorkingDir();
|
|
||||||
Console::printProps($out, $tty_width);
|
|
||||||
|
|
||||||
self::$server->set($this->server_set);
|
self::$server->set($this->server_set);
|
||||||
if (file_exists(DataProvider::getWorkingDir() . "/config/motd.txt")) {
|
|
||||||
$motd = file_get_contents(DataProvider::getWorkingDir() . "/config/motd.txt");
|
// 打印初始信息
|
||||||
} else {
|
$out["listen"] = ZMConfig::get("global", "host") . ":" . ZMConfig::get("global", "port");
|
||||||
$motd = file_get_contents(__DIR__ . "/../../config/motd.txt");
|
if (!isset(ZMConfig::get("global", "swoole")["worker_num"])) $out["worker"] = swoole_cpu_num() . " (auto)";
|
||||||
|
else $out["worker"] = ZMConfig::get("global", "swoole")["worker_num"];
|
||||||
|
$out["env"] = $args["env"] === null ? "default" : $args["env"];
|
||||||
|
$out["log_level"] = Console::getLevel();
|
||||||
|
$out["version"] = ZM_VERSION;
|
||||||
|
if (APP_VERSION !== "unknown") $out["app_version"] = APP_VERSION;
|
||||||
|
if (isset(ZMConfig::get("global", "swoole")["task_worker_num"])) {
|
||||||
|
$out["task_worker"] = ZMConfig::get("global", "swoole")["task_worker_num"];
|
||||||
}
|
}
|
||||||
$motd = explode("\n", $motd);
|
if (ZMConfig::get("global", "sql_config")["sql_host"] !== "") {
|
||||||
foreach ($motd as $k => $v) {
|
$conf = ZMConfig::get("global", "sql_config");
|
||||||
$motd[$k] = substr($v, 0, $tty_width);
|
$out["mysql_pool"] = $conf["database"] . "@" . $conf["sql_host"] . ":" . $conf["sql_port"];
|
||||||
}
|
}
|
||||||
$motd = implode("\n", $motd);
|
if (ZMConfig::get("global", "redis_config")["host"] !== "") {
|
||||||
echo $motd;
|
$conf = ZMConfig::get("global", "redis_config");
|
||||||
|
$out["redis_pool"] = $conf["host"] . ":" . $conf["port"];
|
||||||
|
}
|
||||||
|
if (ZMConfig::get("global", "static_file_server")["status"] !== false) {
|
||||||
|
$out["static_file_server"] = "enabled";
|
||||||
|
}
|
||||||
|
|
||||||
|
$out["working_dir"] = DataProvider::getWorkingDir();
|
||||||
|
self::printProps($out, $tty_width, $args["log-theme"] === null);
|
||||||
|
|
||||||
|
self::printMotd($tty_width);
|
||||||
|
|
||||||
global $asd;
|
global $asd;
|
||||||
$asd = get_included_files();
|
$asd = get_included_files();
|
||||||
// 注册 Swoole Server 的事件
|
// 注册 Swoole Server 的事件
|
||||||
@ -171,6 +174,20 @@ class Framework
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function printMotd($tty_width) {
|
||||||
|
if (file_exists(DataProvider::getWorkingDir() . "/config/motd.txt")) {
|
||||||
|
$motd = file_get_contents(DataProvider::getWorkingDir() . "/config/motd.txt");
|
||||||
|
} else {
|
||||||
|
$motd = file_get_contents(__DIR__ . "/../../config/motd.txt");
|
||||||
|
}
|
||||||
|
$motd = explode("\n", $motd);
|
||||||
|
foreach ($motd as $k => $v) {
|
||||||
|
$motd[$k] = substr($v, 0, $tty_width);
|
||||||
|
}
|
||||||
|
$motd = implode("\n", $motd);
|
||||||
|
echo $motd;
|
||||||
|
}
|
||||||
|
|
||||||
public function start() {
|
public function start() {
|
||||||
self::$server->start();
|
self::$server->start();
|
||||||
}
|
}
|
||||||
@ -280,6 +297,95 @@ class Framework
|
|||||||
if ($coroutine_mode) Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL);
|
if ($coroutine_mode) Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function writeNoDouble($k, $v, &$line_data, &$line_width, &$current_line, $colorful, $max_border) {
|
||||||
|
$tmp_line = $k . ": " . $v;
|
||||||
|
//Console::info("写入[".$tmp_line."]");
|
||||||
|
if (strlen($tmp_line) >= $line_width[$current_line]) { //输出的内容太多了,以至于一行都放不下一个,要折行
|
||||||
|
$title_strlen = strlen($k . ": ");
|
||||||
|
$content_len = $line_width[$current_line] - $title_strlen;
|
||||||
|
|
||||||
|
$line_data[$current_line] = " " . $k . ": ";
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::color8(32);
|
||||||
|
$line_data[$current_line] .= substr($v, 0, $content_len);
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::RESET;
|
||||||
|
$rest = substr($v, $content_len);
|
||||||
|
++$current_line; // 带标题的第一行满了,折到第二行
|
||||||
|
do {
|
||||||
|
if ($colorful) $line_data[$current_line] = TermColor::color8(32);
|
||||||
|
$line_data[$current_line] .= " " . substr($rest, 0, $max_border - 2);
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::RESET;
|
||||||
|
$rest = substr($rest, $max_border - 2);
|
||||||
|
++$current_line;
|
||||||
|
} while ($rest > $max_border - 2); // 循环,直到放完
|
||||||
|
} else { // 不需要折行
|
||||||
|
//Console::info("不需要折行");
|
||||||
|
$line_data[$current_line] = " " . $k . ": ";
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::color8(32);
|
||||||
|
$line_data[$current_line] .= $v;
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::RESET;
|
||||||
|
|
||||||
|
if ($max_border >= 57) {
|
||||||
|
if (strlen($tmp_line) >= intval(($max_border - 2) / 2)) { // 不需要折行,直接输出一个转下一行
|
||||||
|
//Console::info("不需要折行,直接输出一个转下一行");
|
||||||
|
++$current_line;
|
||||||
|
} else { // 输出很小,写到前面并分片
|
||||||
|
//Console::info("输出很小,写到前面并分片");
|
||||||
|
$space = intval($max_border / 2) - 2 - strlen($tmp_line);
|
||||||
|
$line_data[$current_line] .= str_pad("", $space, " ");
|
||||||
|
$line_data[$current_line] .= "| "; // 添加分片
|
||||||
|
$line_width[$current_line] -= (strlen($tmp_line) + 3 + $space);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
++$current_line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function printProps($out, $tty_width, $colorful = true) {
|
||||||
|
$max_border = $tty_width < 65 ? $tty_width : 65;
|
||||||
|
if (LOAD_MODE == 0) echo Console::setColor("* Framework started with source mode.\n", $colorful ? "yellow" : "");
|
||||||
|
echo str_pad("", $max_border, "=") . PHP_EOL;
|
||||||
|
|
||||||
|
$current_line = 0;
|
||||||
|
$line_width = [];
|
||||||
|
$line_data = [];
|
||||||
|
foreach ($out as $k => $v) {
|
||||||
|
if (!isset($line_width[$current_line])) {
|
||||||
|
$line_width[$current_line] = $max_border - 2;
|
||||||
|
}
|
||||||
|
//Console::info("行宽[$current_line]:".$line_width[$current_line]);
|
||||||
|
if ($max_border >= 57) { // 很宽的时候,一行能放两个短行
|
||||||
|
if ($line_width[$current_line] == ($max_border - 2)) { //空行
|
||||||
|
self::writeNoDouble($k, $v, $line_data, $line_width, $current_line, $colorful, $max_border);
|
||||||
|
} else { // 不是空行,已经有东西了
|
||||||
|
$tmp_line = $k . ": " . $v;
|
||||||
|
//Console::info("[$current_line]即将插入后面的东西[".$tmp_line."]");
|
||||||
|
if (strlen($tmp_line) > $line_width[$current_line]) { // 地方不够,另起一行
|
||||||
|
$line_data[$current_line] = str_replace("| ", "", $line_data[$current_line]);
|
||||||
|
++$current_line;
|
||||||
|
$line_data[$current_line] = " " . $k . ": ";
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::color8(32);
|
||||||
|
$line_data[$current_line] .= $v;
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::RESET;
|
||||||
|
++$current_line;
|
||||||
|
} else { // 地方够,直接写到后面并另起一行
|
||||||
|
$line_data[$current_line] .= $k . ": ";
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::color8(32);
|
||||||
|
$line_data[$current_line] .= $v;
|
||||||
|
if ($colorful) $line_data[$current_line] .= TermColor::RESET;
|
||||||
|
++$current_line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // 不够宽,直接写单行
|
||||||
|
self::writeNoDouble($k, $v, $line_data, $line_width, $current_line, $colorful, $max_border);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($line_data as $v) {
|
||||||
|
echo $v . PHP_EOL;
|
||||||
|
}
|
||||||
|
echo str_pad("", $max_border, "=") . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getTtyWidth() {
|
public static function getTtyWidth() {
|
||||||
return explode(" ", trim(exec("stty size")))[1];
|
return explode(" ", trim(exec("stty size")))[1];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use ZM\Utils\DataProvider;
|
|||||||
define("ZM_START_TIME", microtime(true));
|
define("ZM_START_TIME", microtime(true));
|
||||||
define("ZM_DATA", ZMConfig::get("global", "zm_data"));
|
define("ZM_DATA", ZMConfig::get("global", "zm_data"));
|
||||||
define("ZM_VERSION", json_decode(file_get_contents(__DIR__ . "/../../composer.json"), true)["version"] ?? "unknown");
|
define("ZM_VERSION", json_decode(file_get_contents(__DIR__ . "/../../composer.json"), true)["version"] ?? "unknown");
|
||||||
define("APP_VERSION", json_decode(file_get_contents(DataProvider::getWorkingDir() . "/composer.json"), true)["version"] ?? "unknown");
|
define("APP_VERSION", LOAD_MODE == 1 ? (json_decode(file_get_contents(DataProvider::getWorkingDir() . "/composer.json"), true)["version"] ?? "unknown") : "unknown");
|
||||||
define("CRASH_DIR", ZMConfig::get("global", "crash_dir"));
|
define("CRASH_DIR", ZMConfig::get("global", "crash_dir"));
|
||||||
@mkdir(ZM_DATA);
|
@mkdir(ZM_DATA);
|
||||||
@mkdir(CRASH_DIR);
|
@mkdir(CRASH_DIR);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user