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
12namespace Symfony\Component\EventDispatcher;
13
14use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
15
16/**
17 * The EventDispatcherInterface is the central point of Symfony's event listener system.
18 * Listeners are registered on the manager and events are dispatched through the
19 * manager.
20 *
21 * @author Bernhard Schussek <bschussek@gmail.com>
22 */
23interface EventDispatcherInterface extends ContractsEventDispatcherInterface
24{
25    /**
26     * Adds an event listener that listens on the specified events.
27     *
28     * @param int $priority The higher this value, the earlier an event
29     *                      listener will be triggered in the chain (defaults to 0)
30     */
31    public function addListener(string $eventName, callable $listener, int $priority = 0);
32
33    /**
34     * Adds an event subscriber.
35     *
36     * The subscriber is asked for all the events it is
37     * interested in and added as a listener for these events.
38     */
39    public function addSubscriber(EventSubscriberInterface $subscriber);
40
41    /**
42     * Removes an event listener from the specified events.
43     */
44    public function removeListener(string $eventName, callable $listener);
45
46    public function removeSubscriber(EventSubscriberInterface $subscriber);
47
48    /**
49     * Gets the listeners of a specific event or all listeners sorted by descending priority.
50     *
51     * @return array The event listeners for the specified event, or all event listeners by event name
52     */
53    public function getListeners(string $eventName = null);
54
55    /**
56     * Gets the listener priority for a specific event.
57     *
58     * Returns null if the event or the listener does not exist.
59     *
60     * @return int|null The event listener priority
61     */
62    public function getListenerPriority(string $eventName, callable $listener);
63
64    /**
65     * Checks whether an event has any registered listeners.
66     *
67     * @return bool true if the specified event has any listeners, false otherwise
68     */
69    public function hasListeners(string $eventName = null);
70}
71