4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\EventDispatcher;
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
19 * @author Bernhard Schussek <bschussek@gmail.com>
21 interface EventDispatcherInterface
24 * Dispatches an event to all registered listeners.
26 * @param string $eventName The name of the event to dispatch. The name of
27 * the event is the name of the method that is
28 * invoked on listeners.
29 * @param Event $event The event to pass to the event handlers/listeners
30 * If not supplied, an empty Event instance is created
34 public function dispatch($eventName, Event $event = null);
37 * Adds an event listener that listens on the specified events.
39 * @param string $eventName The event to listen on
40 * @param callable $listener The listener
41 * @param int $priority The higher this value, the earlier an event
42 * listener will be triggered in the chain (defaults to 0)
44 public function addListener($eventName, $listener, $priority = 0);
47 * Adds an event subscriber.
49 * The subscriber is asked for all the events he is
50 * interested in and added as a listener for these events.
52 public function addSubscriber(EventSubscriberInterface $subscriber);
55 * Removes an event listener from the specified events.
57 * @param string $eventName The event to remove a listener from
58 * @param callable $listener The listener to remove
60 public function removeListener($eventName, $listener);
62 public function removeSubscriber(EventSubscriberInterface $subscriber);
65 * Gets the listeners of a specific event or all listeners sorted by descending priority.
67 * @param string $eventName The name of the event
69 * @return array The event listeners for the specified event, or all event listeners by event name
71 public function getListeners($eventName = null);
74 * Gets the listener priority for a specific event.
76 * Returns null if the event or the listener does not exist.
78 * @param string $eventName The name of the event
79 * @param callable $listener The listener
81 * @return int|null The event listener priority
83 public function getListenerPriority($eventName, $listener);
86 * Checks whether an event has any registered listeners.
88 * @param string $eventName The name of the event
90 * @return bool true if the specified event has any listeners, false otherwise
92 public function hasListeners($eventName = null);