1 | <?php |
||
14 | class Event { |
||
15 | use |
||
16 | Singleton; |
||
17 | const INIT_STATE_METHOD = 'init'; |
||
18 | /** |
||
19 | * @var callable[][] |
||
20 | */ |
||
21 | protected $callbacks; |
||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | protected $initialized; |
||
26 | protected function init () { |
||
30 | /** |
||
31 | * Add event handler |
||
32 | * |
||
33 | * @param string $event For example `admin/System/components/plugins/disable` |
||
34 | * @param callable $callback Callable, that will be called at event dispatching |
||
35 | * |
||
36 | * @return Event |
||
37 | */ |
||
38 | function on ($event, $callback) { |
||
45 | /** |
||
46 | * Remove event handler |
||
47 | * |
||
48 | * @param string $event |
||
49 | * @param callable|null $callback If not specified - all callbacks for this event will be removed |
||
50 | * |
||
51 | * @return Event |
||
52 | */ |
||
53 | function off ($event, $callback = null) { |
||
69 | /** |
||
70 | * Similar to `::on()`, but but removes handler after handling of first event |
||
71 | * |
||
72 | * @param string $event |
||
73 | * @param callable $callback |
||
74 | * |
||
75 | * @return Event |
||
76 | */ |
||
77 | function once ($event, $callback) { |
||
87 | /** |
||
88 | * Fire event |
||
89 | * |
||
90 | * After event name it is possible to specify as many arguments as needed |
||
91 | * |
||
92 | * @param string $event For example `admin/System/components/plugins/disable` |
||
93 | * @param mixed $param1 |
||
94 | * @param mixed $_ |
||
95 | * |
||
96 | * @return bool |
||
97 | */ |
||
98 | function fire ($event, $param1 = null, $_ = null) { |
||
116 | /** |
||
117 | * Initialize all events handlers |
||
118 | */ |
||
119 | protected function initialize () { |
||
125 | /** |
||
126 | * @return string[] |
||
127 | */ |
||
128 | protected function events_files_paths () { |
||
147 | } |
||
148 |