1 | <?php |
||
18 | class Dispatcher |
||
19 | { |
||
20 | /** |
||
21 | * The registered listeners for this Event Dispatcher |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | private $listeners = array(); |
||
26 | |||
27 | /** |
||
28 | * An associative array mapping each event name to the flag indicating if sorting is required |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | private $sortingRequiredFlags = array(); |
||
33 | |||
34 | /** |
||
35 | * Register a listener with this event dispatcher. |
||
36 | * |
||
37 | * @param string $eventName The name of the event to listen for |
||
38 | * @param callable $callable The callable to dispatch events to |
||
39 | * @param int $priority Optional priority for the listener. Lower is higher. |
||
40 | * @throws \InvalidArgumentException |
||
41 | */ |
||
42 | public function listen($eventName, $callable, $priority = 0) |
||
53 | |||
54 | /** |
||
55 | * Dispatches an event to any associated listeners. |
||
56 | * |
||
57 | * @param Event $event |
||
58 | * @return int The number of listeners fired |
||
59 | */ |
||
60 | public function dispatch($eventName, Event $event) |
||
82 | |||
83 | /** |
||
84 | * Return the registered listeners for each event name |
||
85 | */ |
||
86 | public function getListeners() |
||
100 | |||
101 | /** |
||
102 | * Sort the internal representation of the listener list for an event name. |
||
103 | * |
||
104 | * @param string $eventName |
||
105 | */ |
||
106 | private function sortListeners($eventName) |
||
111 | } |
||
112 |