Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2019-09-12 10:25:26 +0300
committerGitHub <noreply@github.com>2019-09-12 10:25:26 +0300
commitac48a9ba61ec9cb7632bf67328b654f2a628a981 (patch)
tree2dd4f1f7f44fbaf3f2a63ee59bbbf465ef0cb8ac /lib
parent1b8d6df6cdfd2f130b3702d9e183d83183370dd1 (diff)
parentb9e14d5972d403a669a23e11b4b1359995d65ccc (diff)
Merge pull request #17106 from nextcloud/feature/dispatch-typed-event
Add Symfony inspired typed event dispatcher method
Diffstat (limited to 'lib')
-rw-r--r--lib/private/EventDispatcher/EventDispatcher.php5
-rw-r--r--lib/public/EventDispatcher/IEventDispatcher.php12
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/private/EventDispatcher/EventDispatcher.php b/lib/private/EventDispatcher/EventDispatcher.php
index bbf6ae2b368..8830bae79d8 100644
--- a/lib/private/EventDispatcher/EventDispatcher.php
+++ b/lib/private/EventDispatcher/EventDispatcher.php
@@ -31,6 +31,7 @@ use OCP\IContainer;
use OCP\ILogger;
use OCP\IServerContainer;
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
+use function get_class;
class EventDispatcher implements IEventDispatcher {
@@ -74,6 +75,10 @@ class EventDispatcher implements IEventDispatcher {
$this->dispatcher->dispatch($event, $eventName);
}
+ public function dispatchTyped(Event $event): void {
+ $this->dispatch(get_class($event), $event);
+ }
+
/**
* @return SymfonyDispatcher
*/
diff --git a/lib/public/EventDispatcher/IEventDispatcher.php b/lib/public/EventDispatcher/IEventDispatcher.php
index af4d5316a7b..630b7e3c8a0 100644
--- a/lib/public/EventDispatcher/IEventDispatcher.php
+++ b/lib/public/EventDispatcher/IEventDispatcher.php
@@ -58,4 +58,16 @@ interface IEventDispatcher {
*/
public function dispatch(string $eventName, Event $event): void;
+ /**
+ * Dispatch a typed event
+ *
+ * Only use this with subclasses of ``\OCP\EventDispatcher\Event``.
+ * The object's class will determine the event name.
+ *
+ * @param Event $event
+ *
+ * @since 18.0.0
+ */
+ public function dispatchTyped(Event $event): void;
+
}