-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMultiEvent.php
50 lines (44 loc) · 924 Bytes
/
MultiEvent.php
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
<?php
/**
* Created by PhpStorm.
* User: yf
* Date: 2018/5/30
* Time: 下午2:37
*/
namespace EasySwoole\Component;
class MultiEvent extends MultiContainer
{
function set($key, $item)
{
if(is_callable($item)){
return parent::set($key, $item);
}else{
return false;
}
}
function add($key, $item)
{
if(is_callable($item)){
return parent::add($key, $item);
}else{
return false;
}
}
/**
* @param $event
* @param mixed ...$args
* @return array
* @throws \Throwable
*/
public function hook($event, ...$args):array
{
$res = [];
$calls = $this->get($event);
if(is_array($calls)){
foreach ($calls as $key => $call){
$res[$key] = call_user_func($call,...$args);
}
}
return $res;
}
}