1 | <?php |
||
31 | trait ListenerAwareTrait |
||
32 | { |
||
33 | /** |
||
34 | * cache for listeners' event handlers |
||
35 | * |
||
36 | * @var array |
||
37 | * @access protected |
||
38 | */ |
||
39 | protected $listener_cache = []; |
||
40 | |||
41 | /** |
||
42 | * {@inheritDoc} |
||
43 | */ |
||
44 | public function attachListener(ListenerInterface $listener) |
||
55 | |||
56 | /** |
||
57 | * {@inheritDoc} |
||
58 | */ |
||
59 | public function detachListener( |
||
75 | |||
76 | /** |
||
77 | * Get cached listener events (fixed already) |
||
78 | * |
||
79 | * @param ListenerInterface $listener |
||
80 | * @return array |
||
81 | * @access protected |
||
82 | */ |
||
83 | protected function listenerEvents( |
||
92 | |||
93 | /** |
||
94 | * standardize events definition |
||
95 | * |
||
96 | * @param ListenerInterface $listener |
||
97 | * @return array |
||
98 | * @access protected |
||
99 | */ |
||
100 | protected function fixListenerEvents( |
||
114 | |||
115 | /** |
||
116 | * standardize to array of 'method1' or ['method1', 20] |
||
117 | * |
||
118 | * @param mixed $data |
||
119 | * @return array |
||
120 | * @access protected |
||
121 | */ |
||
122 | protected function expandToHandler($data)/*# : array */ |
||
135 | |||
136 | /** |
||
137 | * standardize one 'method1' or ['method1', 20] |
||
138 | * to [eventName, callable, priority] |
||
139 | * |
||
140 | * @param ListenerInterface $listener |
||
141 | * @param string $eventName |
||
142 | * @param mixed $data |
||
143 | * @return array |
||
144 | * @access protected |
||
145 | */ |
||
146 | protected function expandWithPriority( |
||
160 | |||
161 | /** |
||
162 | * standardize 'method' or callable to callable |
||
163 | * |
||
164 | * @param ListenerInterface $listener |
||
165 | * @param mixed $callable |
||
166 | * @return callable |
||
167 | * @access protected |
||
168 | */ |
||
169 | protected function expandCallable( |
||
179 | |||
180 | // from other trait |
||
181 | abstract public function on(/*# string */ $eventName, callable $callable, /*# int */ $priority = 50); |
||
183 | } |
||
184 |