|
| 1 | + |
| 2 | +/** |
| 3 | + * This file is part of the Phalcon Framework. |
| 4 | + * |
| 5 | + * (c) Phalcon Team <team@phalcon.io> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE.txt |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +namespace Phalcon\Contracts\Events; |
| 12 | + |
| 13 | +/** |
| 14 | + * Canonical contract for Phalcon\Events\Manager. |
| 15 | + */ |
| 16 | +interface Manager |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var int |
| 20 | + */ |
| 21 | + const DEFAULT_PRIORITY = 100; |
| 22 | + |
| 23 | + /** |
| 24 | + * Registers an event subscriber. The subscriber's getSubscribedEvents() |
| 25 | + * map is parsed and each entry is attached through the regular listener |
| 26 | + * pipeline. |
| 27 | + */ |
| 28 | + public function addSubscriber(<Subscriber> subscriber) -> void; |
| 29 | + |
| 30 | + /** |
| 31 | + * Returns whether priority ordering is currently enabled. |
| 32 | + */ |
| 33 | + public function arePrioritiesEnabled() -> bool; |
| 34 | + |
| 35 | + /** |
| 36 | + * Attach a listener to the events manager. |
| 37 | + * |
| 38 | + * @param object|callable handler |
| 39 | + */ |
| 40 | + public function attach( |
| 41 | + string eventType, |
| 42 | + handler, |
| 43 | + int priority = self::DEFAULT_PRIORITY |
| 44 | + ) -> void; |
| 45 | + |
| 46 | + /** |
| 47 | + * Removes every registered subscriber and detaches each listener they |
| 48 | + * contributed. Listeners attached via attach() are untouched. |
| 49 | + */ |
| 50 | + public function clearSubscribers() -> void; |
| 51 | + |
| 52 | + /** |
| 53 | + * Toggle response collection on/off. |
| 54 | + */ |
| 55 | + public function collectResponses(bool collect) -> void; |
| 56 | + |
| 57 | + /** |
| 58 | + * Detach a listener from the events manager. |
| 59 | + * |
| 60 | + * @param object|callable handler |
| 61 | + */ |
| 62 | + public function detach(string eventType, handler) -> void; |
| 63 | + |
| 64 | + /** |
| 65 | + * Removes all listeners — globally or for a single event type. |
| 66 | + */ |
| 67 | + public function detachAll(string type = null) -> void; |
| 68 | + |
| 69 | + /** |
| 70 | + * Toggle priority ordering on/off. |
| 71 | + */ |
| 72 | + public function enablePriorities(bool enablePriorities) -> void; |
| 73 | + |
| 74 | + /** |
| 75 | + * Fires an event, notifying the active listeners. |
| 76 | + * |
| 77 | + * @param object source |
| 78 | + * @param mixed data |
| 79 | + * @return mixed |
| 80 | + */ |
| 81 | + public function fire( |
| 82 | + string eventType, |
| 83 | + object source, |
| 84 | + var data = null, |
| 85 | + bool cancelable = true |
| 86 | + ); |
| 87 | + |
| 88 | + /** |
| 89 | + * Returns all listeners attached to the given event type. |
| 90 | + */ |
| 91 | + public function getListeners(string type) -> array; |
| 92 | + |
| 93 | + /** |
| 94 | + * Returns the responses recorded during the last fire (when collecting). |
| 95 | + */ |
| 96 | + public function getResponses() -> array; |
| 97 | + |
| 98 | + /** |
| 99 | + * Returns the list of registered subscriber instances. |
| 100 | + */ |
| 101 | + public function getSubscribers() -> array; |
| 102 | + |
| 103 | + /** |
| 104 | + * Check whether the given event type has any listeners. |
| 105 | + */ |
| 106 | + public function hasListeners(string type) -> bool; |
| 107 | + |
| 108 | + /** |
| 109 | + * Check whether the manager is currently collecting responses. |
| 110 | + */ |
| 111 | + public function isCollecting() -> bool; |
| 112 | + |
| 113 | + /** |
| 114 | + * Returns true when the given handler is an object or callable. |
| 115 | + */ |
| 116 | + public function isValidHandler(var handler) -> bool; |
| 117 | + |
| 118 | + /** |
| 119 | + * Removes a previously registered subscriber. Detaches every listener the |
| 120 | + * subscriber declared via getSubscribedEvents(). Idempotent. |
| 121 | + */ |
| 122 | + public function removeSubscriber(<Subscriber> subscriber) -> void; |
| 123 | +} |
0 commit comments