update to build 420

This commit is contained in:
crazywhalecc 2021-09-11 11:59:02 +08:00
parent 07391810ff
commit 907a9cea25
11 changed files with 102 additions and 21 deletions

View File

@ -14,7 +14,6 @@ src/
   │   └── zm.json
   └── Middleware/
   └── TimerMiddleware.php
```
我们在 Example 目录下创建一个 `zm.json` 的文件,编写配置,即代表 `src/Module/Example/` 文件夹及里面的用户模块源码为一个模块包,也就可以被框架识别并打包处理。
@ -160,6 +159,68 @@ src/
在打包时框架会自动添加这些文件到 phar 插件包内,到解包时,会自动将这些文件释放到对应框架的 `zm_data` 目录下。
## 打包模块命令
编写配置文件 `zm.json` 后,就可以被框架正常识别为模块形式,你也可以使用对无需打包的模块进行配置以进行分类管理。
### module:list
使用 list 命令可以列出炸毛框架检测到配置文件或打包好的模块。
```
$ ./zhamao module:list
[foo]
类型: source
版本: 1.0.0
描述: 示例模块打包文件
目录: src/Module/Example
没有发现已打包且装载的模块!
```
其中 `[ ]` 内为识别出来的模块名称,由上方用户编写的 `zm.json` 定义,类型为 `source` 是源码形式,也就是指定了 `zm.json` 形式的模块,目录为模块所在子目录。
我们假设打包上方定义的 `foo` 模块,使用下方命令 `module:pack` 即可。
### module:pack
使用 pack 命令可以将配置好的模块打包为 `xxx.phar` 文件并转移或发布给他人。
我们假设打包模块脚手架的默认模块 `src/Module/Example` 下面的模块源码和附带一个 `zm_data` 目录下的文件(我们就随便打包一下 Swoole 的输出日志吧)。`zm.json` 文件内容如下:
```json
{
"name": "foo",
"description": "示例模块打包文件",
"version": "1.0.0",
"allow-hotload": true,
"zm-data-store": [
"crash/swoole_error.log"
]
}
```
然后输入命令:
```
$ ./zhamao module:pack foo
[15:07:11] [I] 模块输出文件:/root/zhamao-framework/zm_data/output/foo_1.0.0.phar
[15:07:11] [S] 打包完成!
```
如果提示文件夹不存在,请先手动创建文件夹:`mkdir /path/to/your/zm_data/output`
在打包后,你将获得一个 `foo_1.0.0.phar` 的文件。
> 如果你没有在 `zm.json` 中指定 `version`,那么输出的 phar 文件是不会带版本号的。
打包后的 phar 内将包含:
- Hello.php
- zm.json
- crash/swoole_error.log
- 必要的框架热加载以及解包需要的配置信息
## 打包命令
```bash

View File

@ -3,7 +3,7 @@
> 本文档为炸毛框架 v2 版本,如需查看 v1 版本,[点我](https://docs-v1.zhamao.xin/)。
!!! tip "提示"
编写文档需要较大精力,你也可以参与到本文档的建设中来,比如找错字,增加或更正内容,每页文档可直接点击右上方铅笔图标直接跳转至 GitHub 进行编辑,编辑后自动 Fork 并生成 Pull Request以此来贡献此文档
炸毛框架使用 PHP 编写,采用 Swoole 扩展为基础,主要面向 API 服务聊天机器人OneBot 标准的机器人对接),包含 WebSocket、HTTP 等监听和请求库,用户代码采用模块化处理,使用注解可以方便地编写各类功能。

View File

@ -4,6 +4,16 @@
同时此处将只使用 build 版本号进行区分。
## build 420 (2021-9-11)
- 修复 OneBot 事件无法响应的 bug
- 新增部分 EventDispatcher 触发的事件 debug 日志
## build 419 (2021-9-11)
- 修复 DB 模块在未连接数据库的时候抛出未知异常
- 修复部分情况下打包模块出现的错误
## build 418 (2021-9-10)
- 修复 ZMAtomic 在 test 环境下的 bug

View File

@ -52,7 +52,7 @@ class ModulePackCommand extends Command
$output->writeln("<error>不存在模块 ".$input->getArgument("module-name")." !</error>");
return 1;
}
$result = ModuleManager::packModule($list[$input->getArgument("module-name")]);
$result = ModuleManager::packModule($list[$input->getArgument("module-name")], $input->getOption("target"));
if ($result) Console::success("打包完成!");
else Console::error("打包失败!");
return 0;

View File

@ -28,7 +28,7 @@ class ConsoleApplication extends Application
{
private static $obj = null;
const VERSION_ID = 419;
const VERSION_ID = 420;
const VERSION = "2.5.3";
/**

View File

@ -72,11 +72,13 @@ class EventDispatcher
}
public function setRuleFunction(callable $rule = null): EventDispatcher {
if ($this->log) Console::verbose("[事件分发{$this->eid}] 设置事件rule: " . $this->class);
$this->rule = $rule;
return $this;
}
public function setReturnFunction(callable $return_func): EventDispatcher {
if ($this->log) Console::verbose("[事件分发{$this->eid}] 设置事件returnFunc: " . $this->class);
$this->return_func = $return_func;
return $this;
}

View File

@ -23,6 +23,7 @@ class EventManager
public static $req_mapping = [];
public static function addEvent($event_name, ?AnnotationBase $event_obj) {
Console::debug("Adding event $event_name at ".$event_obj->class.":".$event_obj->method);
self::$events[$event_name][] = $event_obj;
(new AnnotationParser())->sortByLevel(self::$events, $event_name);
}

View File

@ -25,6 +25,9 @@ use ZM\Event\SwooleEvent;
*/
class OnMessage implements SwooleEvent
{
/**
* @noinspection PhpUnreachableStatementInspection
*/
public function onCall($server, Frame $frame) {
Console::debug("Calling Swoole \"message\" from fd=" . $frame->fd . ": " . TermColor::ITALIC . $frame->data . TermColor::RESET);
unset(Context::$context[Coroutine::getCid()]);
@ -32,8 +35,8 @@ class OnMessage implements SwooleEvent
set_coroutine_params(["server" => $server, "frame" => $frame, "connection" => $conn]);
$dispatcher1 = new EventDispatcher(OnMessageEvent::class);
$dispatcher1->setRuleFunction(function ($v) {
/** @noinspection PhpUnreachableStatementInspection */
return ctx()->getConnection()->getName() == $v->connect_type && eval("return " . $v->getRule() . ";");
if ($v->getRule() == '') return true;
else return eval("return " . $v->getRule() . ";");
});

View File

@ -12,6 +12,7 @@ use Swoole\Database\PDOConfig;
use Swoole\Process;
use Swoole\Server;
use ZM\Annotation\AnnotationParser;
use ZM\Annotation\Swoole\OnMessageEvent;
use ZM\Annotation\Swoole\OnStart;
use ZM\Annotation\Swoole\OnSwooleEvent;
use ZM\Annotation\Swoole\SwooleHandler;
@ -157,21 +158,7 @@ class OnWorkerStart implements SwooleEvent
ZMConfig::get("global", "modules")["onebot"] ??
["status" => true, "single_bot_mode" => false, "message_level" => 99999];
if ($obb_onebot["status"]) {
Console::debug("OneBot support enabled, listening OneBot event(3).");
$obj = new OnSwooleEvent();
$obj->class = QQBot::class;
$obj->method = 'handleByEvent';
$obj->type = 'message';
$obj->level = $obb_onebot["message_level"] ?? 99999;
$obj->rule = 'connectIsQQ()';
EventManager::addEvent(OnSwooleEvent::class, $obj);
if ($obb_onebot["single_bot_mode"]) {
LightCacheInside::set("connect", "conn_fd", -1);
} else {
LightCacheInside::set("connect", "conn_fd", -2);
}
}
// 检查是否允许热加载phar模块允许的话将遍历phar内的文件
$plugin_enable_hotload = ZMConfig::get("global", "module_loader")["enable_hotload"] ?? false;
@ -188,6 +175,22 @@ class OnWorkerStart implements SwooleEvent
$parser->registerMods();
EventManager::loadEventByParser($parser); //加载事件
if ($obb_onebot["status"]) {
Console::debug("OneBot support enabled, listening OneBot event(3).");
$obj = new OnMessageEvent();
$obj->class = QQBot::class;
$obj->method = 'handleByEvent';
$obj->level = $obb_onebot["message_level"] ?? 99999;
$obj->rule = 'connectIsQQ()';
EventManager::addEvent(OnMessageEvent::class, $obj);
zm_dump(EventManager::$events[OnMessageEvent::class]);
if ($obb_onebot["single_bot_mode"]) {
LightCacheInside::set("connect", "conn_fd", -1);
} else {
LightCacheInside::set("connect", "conn_fd", -2);
}
}
}
private function initMySQLPool() {

View File

@ -54,6 +54,7 @@ class ModulePacker
*/
public function setOutputPath($path) {
$this->output_path = $path;
if (!is_dir($path)) mkdir($path, 0755, true);
}
/**

0
zhamao Normal file → Executable file
View File