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