Event.php
1011 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Event;
/**
* 事件
* @author:dc
* @time 2024/9/30 16:33
* Class Event
* @package Event
*/
class Event {
/**
* 同步
* @var array
*/
protected static $alias = [
// 列表同步成功后
'mail_sync_list' => [
SyncMail::class,
// MailBlack::class
],
];
/**
* @param $name
* @param mixed ...$params
* @throws \Exception
* @author:dc
* @time 2024/9/30 16:55
*/
public static function call($name, ...$params){
// 是否已配置
if(isset(self::$alias[$name])){
array_map(function ($v) use ($params){
new $v(...$params);
},
is_array(self::$alias[$name])? self::$alias[$name] : [is_array(self::$alias[$name])]
);
}else if (class_exists($name)){
new $name(...$params);
}else{
throw new \Exception('event '.$name.' not found');
}
}
}