1 | <?php |
||
12 | class Event { |
||
13 | use |
||
14 | Singleton; |
||
15 | const INIT_STATE_METHOD = 'init'; |
||
16 | /** |
||
17 | * @var callable[][] |
||
18 | */ |
||
19 | protected $callbacks = []; |
||
20 | /** |
||
21 | * @var callable[][] |
||
22 | */ |
||
23 | protected $callbacks_cache; |
||
24 | 72 | protected function construct () { |
|
45 | /** |
||
46 | * Add event handler |
||
47 | * |
||
48 | * @param string $event For example `admin/System/modules/disable` |
||
49 | * @param callable $callback Callable, that will be called at event dispatching |
||
50 | * |
||
51 | * @return Event |
||
52 | */ |
||
53 | 72 | public function on ($event, $callback) { |
|
60 | /** |
||
61 | * Remove event handler |
||
62 | * |
||
63 | * @param string $event |
||
64 | * @param callable|null $callback If not specified - all callbacks for this event will be removed |
||
65 | * |
||
66 | * @return Event |
||
67 | */ |
||
68 | 8 | public function off ($event, $callback = null) { |
|
84 | /** |
||
85 | * Similar to `::on()`, but but removes handler after handling of first event |
||
86 | * |
||
87 | * @param string $event |
||
88 | * @param callable $callback |
||
89 | * |
||
90 | * @return Event |
||
91 | */ |
||
92 | 10 | public function once ($event, $callback) { |
|
102 | /** |
||
103 | * Fire event |
||
104 | * |
||
105 | * After event name it is possible to specify as many arguments as needed |
||
106 | * |
||
107 | * @param string $event For example `admin/System/modules/disable` |
||
108 | * @param mixed[] $arguments |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | 70 | public function fire ($event, ...$arguments) { |
|
126 | /** |
||
127 | * @return string[] |
||
128 | */ |
||
129 | 72 | protected function events_files_paths () { |
|
138 | } |
||
139 |