Skip to content
Snippets Groups Projects
Unverified Commit ac48a9ba authored by blizzz's avatar blizzz Committed by GitHub
Browse files

Merge pull request #17106 from nextcloud/feature/dispatch-typed-event

Add Symfony inspired typed event dispatcher method
parents 1b8d6df6 b9e14d59
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ use OCP\IContainer; ...@@ -31,6 +31,7 @@ use OCP\IContainer;
use OCP\ILogger; use OCP\ILogger;
use OCP\IServerContainer; use OCP\IServerContainer;
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher; use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
use function get_class;
class EventDispatcher implements IEventDispatcher { class EventDispatcher implements IEventDispatcher {
...@@ -74,6 +75,10 @@ class EventDispatcher implements IEventDispatcher { ...@@ -74,6 +75,10 @@ class EventDispatcher implements IEventDispatcher {
$this->dispatcher->dispatch($event, $eventName); $this->dispatcher->dispatch($event, $eventName);
} }
public function dispatchTyped(Event $event): void {
$this->dispatch(get_class($event), $event);
}
/** /**
* @return SymfonyDispatcher * @return SymfonyDispatcher
*/ */
......
...@@ -58,4 +58,16 @@ interface IEventDispatcher { ...@@ -58,4 +58,16 @@ interface IEventDispatcher {
*/ */
public function dispatch(string $eventName, Event $event): void; 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;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment