mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 07:35:34 +08:00
extend event compatibility
This commit is contained in:
@@ -8,6 +8,7 @@ use Framework\ZMBuf;
|
||||
use ZM\Annotation\CQ\CQBefore;
|
||||
use ZM\Annotation\CQ\CQMetaEvent;
|
||||
use ZM\Connection\ConnectionManager;
|
||||
use ZM\Connection\CQConnection;
|
||||
use ZM\Exception\WaitTimeoutException;
|
||||
use ZM\ModBase;
|
||||
use ZM\ModHandleType;
|
||||
@@ -15,25 +16,23 @@ use ZM\ModHandleType;
|
||||
class MetaEvent
|
||||
{
|
||||
private $data;
|
||||
/** @var \ZM\Event\Swoole\MessageEvent */
|
||||
private $swoole_event;
|
||||
/** @var CQConnection */
|
||||
private $connection;
|
||||
private $circle;
|
||||
|
||||
public function __construct($data, \ZM\Event\Swoole\MessageEvent $event, $circle = 0) {
|
||||
public function __construct($data, $connection, $circle = 0) {
|
||||
$this->data = $data;
|
||||
$this->swoole_event = $event;
|
||||
$this->connection = $connection;
|
||||
$this->circle = $circle;
|
||||
}
|
||||
|
||||
public function onBefore() {
|
||||
foreach (ZMBuf::$events[CQBefore::class][CQMetaEvent::class] ?? [] as $v) {
|
||||
foreach (ZMBuf::$events[CQBefore::class]["meta_event"] ?? [] as $v) {
|
||||
$c = $v->class;
|
||||
/** @var CQMetaEvent $v */
|
||||
$class = new $c([
|
||||
"data" => $this->data,
|
||||
"frame" => $this->swoole_event->frame,
|
||||
"server" => $this->swoole_event->server,
|
||||
"connection" => ConnectionManager::get($this->swoole_event->frame->fd)
|
||||
"connection" => $this->connection
|
||||
], ModHandleType::CQ_META_EVENT);
|
||||
$r = call_user_func_array([$class, $v->method], []);
|
||||
if (!$r || $class->block_continue) return false;
|
||||
@@ -55,9 +54,7 @@ class MetaEvent
|
||||
if (!isset($obj[$c]))
|
||||
$obj[$c] = new $c([
|
||||
"data" => $this->data,
|
||||
"frame" => $this->swoole_event->frame,
|
||||
"server" => $this->swoole_event->server,
|
||||
"connection" => ConnectionManager::get($this->swoole_event->frame->fd)
|
||||
"connection" => $this->connection
|
||||
], ModHandleType::CQ_META_EVENT);
|
||||
$r = call_user_func([$obj[$c], $v->method]);
|
||||
if (is_string($r)) $obj[$c]->reply($r);
|
||||
|
||||
Reference in New Issue
Block a user