|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony package. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.com> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace Symfony\Component\EventDispatcher; |
|
13 |
|
14 /** |
|
15 * The EventDispatcherInterface is the central point of Symfony's event listener system. |
|
16 * Listeners are registered on the manager and events are dispatched through the |
|
17 * manager. |
|
18 * |
|
19 * @author Bernhard Schussek <bschussek@gmail.com> |
|
20 * |
|
21 * @api |
|
22 */ |
|
23 interface EventDispatcherInterface |
|
24 { |
|
25 /** |
|
26 * Dispatches an event to all registered listeners. |
|
27 * |
|
28 * @param string $eventName The name of the event to dispatch. The name of |
|
29 * the event is the name of the method that is |
|
30 * invoked on listeners. |
|
31 * @param Event $event The event to pass to the event handlers/listeners. |
|
32 * If not supplied, an empty Event instance is created. |
|
33 * |
|
34 * @api |
|
35 */ |
|
36 function dispatch($eventName, Event $event = null); |
|
37 |
|
38 /** |
|
39 * Adds an event listener that listens on the specified events. |
|
40 * |
|
41 * @param string $eventName The event to listen on |
|
42 * @param callable $listener The listener |
|
43 * @param integer $priority The higher this value, the earlier an event |
|
44 * listener will be triggered in the chain (defaults to 0) |
|
45 * |
|
46 * @api |
|
47 */ |
|
48 function addListener($eventName, $listener, $priority = 0); |
|
49 |
|
50 /** |
|
51 * Adds an event subscriber. The subscriber is asked for all the events he is |
|
52 * interested in and added as a listener for these events. |
|
53 * |
|
54 * @param EventSubscriberInterface $subscriber The subscriber. |
|
55 * |
|
56 * @api |
|
57 */ |
|
58 function addSubscriber(EventSubscriberInterface $subscriber); |
|
59 |
|
60 /** |
|
61 * Removes an event listener from the specified events. |
|
62 * |
|
63 * @param string|array $eventName The event(s) to remove a listener from. |
|
64 * @param object $listener The listener object to remove. |
|
65 */ |
|
66 function removeListener($eventName, $listener); |
|
67 |
|
68 /** |
|
69 * Removes an event subscriber. |
|
70 * |
|
71 * @param EventSubscriberInterface $subscriber The subscriber. |
|
72 */ |
|
73 function removeSubscriber(EventSubscriberInterface $subscriber); |
|
74 |
|
75 /** |
|
76 * Gets the listeners of a specific event or all listeners. |
|
77 * |
|
78 * @param string $eventName The name of the event. |
|
79 * |
|
80 * @return array The event listeners for the specified event, or all event |
|
81 * listeners by event name. |
|
82 */ |
|
83 function getListeners($eventName = null); |
|
84 |
|
85 /** |
|
86 * Checks whether an event has any registered listeners. |
|
87 * |
|
88 * @param string $eventName The name of the event. |
|
89 * |
|
90 * @return Boolean TRUE if the specified event has any listeners, FALSE |
|
91 * otherwise. |
|
92 */ |
|
93 function hasListeners($eventName = null); |
|
94 } |