Total Complexity | 5 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class EventsHandler |
||
8 | { |
||
9 | /** |
||
10 | * List of events name and its handlers |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | public $events = []; |
||
15 | |||
16 | /** |
||
17 | * @var Client |
||
18 | */ |
||
19 | protected $client; |
||
20 | |||
21 | /** |
||
22 | * Handle api hooks |
||
23 | * |
||
24 | * @param $name |
||
25 | * @param $data |
||
26 | */ |
||
27 | public function run($name, $data) |
||
28 | { |
||
29 | if (! array_key_exists($name, $this->events)) |
||
30 | throw new \BadMethodCallException; |
||
31 | |||
32 | if (is_callable($this->events[$name])) |
||
33 | call_user_func($this->events[$name], $data); |
||
34 | else |
||
35 | call_user_func([$this, $this->events[$name]], $data); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Assign api hook handler |
||
40 | * |
||
41 | * @param $name |
||
42 | * @param Closure $closure |
||
43 | * @return $this |
||
44 | */ |
||
45 | public function assign($name, Closure $closure) |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param $client |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function setClient($client) |
||
61 | } |
||
62 | } |
||
63 |