update to 2.5.0-b2 (build 409)

This commit is contained in:
crazywhalecc
2021-07-04 15:45:30 +08:00
parent 4ee16d4fc6
commit 7ec847e576
28 changed files with 467 additions and 87 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace ZM\Event;
use ZM\Annotation\AnnotationBase;
class EventTracer
{
/**
* 获取当前注解事件的注解类如CQCommand对象
* @return AnnotationBase|null
*/
public static function getCurrentEvent() {
$list = debug_backtrace();
foreach ($list as $v) {
if ((($v["object"] ?? null) instanceof EventDispatcher) && $v["function"] == "dispatchEvent") {
return $v["args"][0];
}
}
return null;
}
/**
* 获取当前注解事件的中间件列表
* @return array|mixed|null
*/
public static function getCurrentEventMiddlewares() {
$current_event = self::getCurrentEvent();
if (!isset($current_event->class, $current_event->method)) return null;
return EventManager::$middleware_map[$current_event->class][$current_event->method] ?? [];
}
public static function getEventTraceList() {
$result = [];
$list = debug_backtrace();
foreach ($list as $v) {
if ((($v["object"] ?? null) instanceof EventDispatcher) && $v["function"] == "dispatchEvent") {
$result[] = $v["args"][0];
}
}
return $result;
}
}