mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-02 14:25:38 +08:00
fix middleware args resolve conflict (#282)
This commit is contained in:
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Module\Example;
|
||||
|
||||
use Choir\WebSocket\FrameInterface;
|
||||
use OneBot\Driver\Coroutine\Adaptive;
|
||||
use OneBot\Driver\Event\WebSocket\WebSocketMessageEvent;
|
||||
use ZM\Annotation\Framework\BindEvent;
|
||||
use ZM\Annotation\Framework\Cron;
|
||||
use ZM\Annotation\Http\Route;
|
||||
use ZM\Annotation\Middleware\Middleware;
|
||||
@@ -19,14 +21,15 @@ use ZM\Middleware\TimerMiddleware;
|
||||
class Hello123
|
||||
{
|
||||
#[Route('/route', request_method: ['GET'])]
|
||||
#[Route('/route/{id}', request_method: ['GET'])]
|
||||
#[Middleware(TimerMiddleware::class)]
|
||||
public function route()
|
||||
public function route(array $params)
|
||||
{
|
||||
return 'Hello Zhamao!This is the first 3.0 page!';
|
||||
return 'Hello Zhamao!This is the first 3.0 page!' . ($params['id'] ?? '');
|
||||
}
|
||||
|
||||
#[BotEvent()]
|
||||
public function onOBEvent(\OneBotEvent $event, WebSocketMessageEvent $messageEvent): void
|
||||
public function onOBEvent(WebSocketMessageEvent $messageEvent, \OneBotEvent $event): void
|
||||
{
|
||||
logger()->info("收到了 {$event->getType()}.{$event->getDetailType()} 事件");
|
||||
}
|
||||
@@ -39,6 +42,12 @@ class Hello123
|
||||
$context->reply($event->getMessage());
|
||||
}
|
||||
|
||||
#[BindEvent(WebSocketMessageEvent::class)]
|
||||
public function onWSMessage(FrameInterface $frame, WebSocketMessageEvent $event): void
|
||||
{
|
||||
logger()->info('收到了 WebSocket 消息');
|
||||
}
|
||||
|
||||
#[Cron('* * * * *', no_overlap: true)]
|
||||
public function logTime(): void
|
||||
{
|
||||
|
||||
@@ -94,6 +94,9 @@ class MiddlewareHandler
|
||||
}
|
||||
}
|
||||
if ($return !== false) {
|
||||
// $args 传递数字索引可能会在部分情况下引发解析错误,应尽量避免
|
||||
// 并尽量避免传递已经绑定入容器的实例
|
||||
// TODO: 可能需要更好的解决方案
|
||||
$result = container()->call($callback, $args);
|
||||
}
|
||||
while (isset($this->stack[$stack_id]) && ($item = array_pop($this->stack[$stack_id])) !== null) {
|
||||
|
||||
@@ -75,9 +75,9 @@ class OneBot12Adapter extends ZMPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal 只允许内部使用
|
||||
* @param int $cid 协程 ID
|
||||
* @param OneBotEvent $event 事件对象
|
||||
* @internal 只允许内部使用
|
||||
*/
|
||||
public static function addContextPrompt(int $cid, OneBotEvent $event): void
|
||||
{
|
||||
@@ -85,8 +85,8 @@ class OneBot12Adapter extends ZMPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal 只允许内部使用
|
||||
* @param int $cid 协程 ID
|
||||
* @internal 只允许内部使用
|
||||
*/
|
||||
public static function removeContextPrompt(int $cid): void
|
||||
{
|
||||
@@ -94,8 +94,8 @@ class OneBot12Adapter extends ZMPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal 只允许内部使用
|
||||
* @param int $cid 协程 ID
|
||||
* @internal 只允许内部使用
|
||||
*/
|
||||
public static function isContextPromptExists(int $cid): bool
|
||||
{
|
||||
@@ -347,7 +347,7 @@ class OneBot12Adapter extends ZMPlugin
|
||||
&& ($event->detail_type === null || $event->detail_type === $obj->detail_type);
|
||||
});
|
||||
try {
|
||||
$handler->handleAll($obj);
|
||||
$handler->handleAll();
|
||||
} catch (WaitTimeoutException $e) {
|
||||
// 这里是处理 prompt() 下超时的情况的
|
||||
if ($e->getTimeoutPrompt() === null) {
|
||||
|
||||
Reference in New Issue
Block a user