From 3ffed429256a1634d0103188ddb5e211616cc355 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 27 Feb 2020 11:01:29 +0100 Subject: [PATCH] Allow to remove listeners Signed-off-by: Joas Schilling --- lib/private/EventDispatcher/EventDispatcher.php | 5 +++++ lib/public/EventDispatcher/IEventDispatcher.php | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/private/EventDispatcher/EventDispatcher.php b/lib/private/EventDispatcher/EventDispatcher.php index 9baa8fc951..4f83d15bff 100644 --- a/lib/private/EventDispatcher/EventDispatcher.php +++ b/lib/private/EventDispatcher/EventDispatcher.php @@ -63,6 +63,11 @@ class EventDispatcher implements IEventDispatcher { $this->dispatcher->addListener($eventName, $listener, $priority); } + public function removeListener(string $eventName, + callable $listener): void { + $this->dispatcher->removeListener($eventName, $listener); + } + public function addServiceListener(string $eventName, string $className, int $priority = 0): void { diff --git a/lib/public/EventDispatcher/IEventDispatcher.php b/lib/public/EventDispatcher/IEventDispatcher.php index e8b63e6f03..e6e1bc5ce6 100644 --- a/lib/public/EventDispatcher/IEventDispatcher.php +++ b/lib/public/EventDispatcher/IEventDispatcher.php @@ -42,6 +42,14 @@ interface IEventDispatcher { */ public function addListener(string $eventName, callable $listener, int $priority = 0): void; + /** + * @param string $eventName preferably the fully-qualified class name of the Event sub class + * @param callable $listener the object that is invoked when a matching event is dispatched + * + * @since 19.0.0 + */ + public function removeListener(string $eventName, callable $listener): void; + /** * @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for * @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container