1<?php
2
3namespace Sabre\Event;
4
5/**
6 * Event Emitter Interface
7 *
8 * Anything that accepts listeners and emits events should implement this
9 * interface.
10 *
11 * @copyright Copyright (C) 2013-2015 fruux GmbH (https://fruux.com/).
12 * @author Evert Pot (http://evertpot.com/)
13 * @license http://sabre.io/license/ Modified BSD License
14 */
15interface EventEmitterInterface {
16
17    /**
18     * Subscribe to an event.
19     *
20     * @param string $eventName
21     * @param callable $callBack
22     * @param int $priority
23     * @return void
24     */
25    function on($eventName, callable $callBack, $priority = 100);
26
27    /**
28     * Subscribe to an event exactly once.
29     *
30     * @param string $eventName
31     * @param callable $callBack
32     * @param int $priority
33     * @return void
34     */
35    function once($eventName, callable $callBack, $priority = 100);
36
37    /**
38     * Emits an event.
39     *
40     * This method will return true if 0 or more listeners were succesfully
41     * handled. false is returned if one of the events broke the event chain.
42     *
43     * If the continueCallBack is specified, this callback will be called every
44     * time before the next event handler is called.
45     *
46     * If the continueCallback returns false, event propagation stops. This
47     * allows you to use the eventEmitter as a means for listeners to implement
48     * functionality in your application, and break the event loop as soon as
49     * some condition is fulfilled.
50     *
51     * Note that returning false from an event subscriber breaks propagation
52     * and returns false, but if the continue-callback stops propagation, this
53     * is still considered a 'successful' operation and returns true.
54     *
55     * Lastly, if there are 5 event handlers for an event. The continueCallback
56     * will be called at most 4 times.
57     *
58     * @param string $eventName
59     * @param array $arguments
60     * @param callback $continueCallBack
61     * @return bool
62     */
63    function emit($eventName, array $arguments = [], callable $continueCallBack = null);
64
65    /**
66     * Returns the list of listeners for an event.
67     *
68     * The list is returned as an array, and the list of events are sorted by
69     * their priority.
70     *
71     * @param string $eventName
72     * @return callable[]
73     */
74    function listeners($eventName);
75
76    /**
77     * Removes a specific listener from an event.
78     *
79     * If the listener could not be found, this method will return false. If it
80     * was removed it will return true.
81     *
82     * @param string $eventName
83     * @param callable $listener
84     * @return bool
85     */
86    function removeListener($eventName, callable $listener);
87
88    /**
89     * Removes all listeners.
90     *
91     * If the eventName argument is specified, all listeners for that event are
92     * removed. If it is not specified, every listener for every event is
93     * removed.
94     *
95     * @param string $eventName
96     * @return void
97     */
98    function removeAllListeners($eventName = null);
99
100}
101