1 | <?php |
||
2 | |||
3 | namespace TelegramBot\Api\Events; |
||
4 | |||
5 | use TelegramBot\Api\Types\Update; |
||
6 | |||
7 | class Event |
||
8 | { |
||
9 | /** |
||
10 | * @var \Closure|null |
||
11 | */ |
||
12 | protected $checker; |
||
13 | |||
14 | /** |
||
15 | * @var \Closure |
||
16 | */ |
||
17 | protected $action; |
||
18 | |||
19 | /** |
||
20 | * Event constructor. |
||
21 | * |
||
22 | * @param \Closure $action |
||
23 | * @param \Closure|null $checker |
||
24 | */ |
||
25 | public function __construct(\Closure $action, \Closure $checker = null) |
||
26 | 11 | { |
|
27 | $this->action = $action; |
||
28 | 11 | $this->checker = $checker; |
|
29 | 11 | } |
|
30 | 11 | ||
31 | /** |
||
32 | * @return \Closure |
||
33 | */ |
||
34 | public function getAction() |
||
35 | 1 | { |
|
36 | return $this->action; |
||
37 | 1 | } |
|
38 | |||
39 | /** |
||
40 | * @return \Closure|null |
||
41 | */ |
||
42 | public function getChecker() |
||
43 | 2 | { |
|
44 | return $this->checker; |
||
45 | 2 | } |
|
46 | |||
47 | /** |
||
48 | * @return mixed |
||
49 | */ |
||
50 | public function executeChecker(Update $message) |
||
51 | { |
||
52 | if (is_callable($this->checker)) { |
||
53 | 3 | return call_user_func($this->checker, $message); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
54 | } |
||
55 | 3 | ||
56 | 2 | return false; |
|
57 | } |
||
58 | |||
59 | 1 | /** |
|
60 | * @return mixed |
||
61 | */ |
||
62 | public function executeAction(Update $message) |
||
63 | { |
||
64 | return call_user_func($this->action, $message); |
||
65 | } |
||
66 | } |
||
67 |