diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Broadcast/Events/BroadcastEvent.php | 59 | ||||
-rw-r--r-- | lib/private/EventDispatcher/EventDispatcher.php | 11 |
2 files changed, 70 insertions, 0 deletions
diff --git a/lib/private/Broadcast/Events/BroadcastEvent.php b/lib/private/Broadcast/Events/BroadcastEvent.php new file mode 100644 index 00000000000..f3282b5207c --- /dev/null +++ b/lib/private/Broadcast/Events/BroadcastEvent.php @@ -0,0 +1,59 @@ +<?php declare(strict_types=1); + +/** + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Broadcast\Events; + +use JsonSerializable; +use OCP\Broadcast\Events\IBroadcastEvent; +use OCP\EventDispatcher\ABroadcastedEvent; +use OCP\EventDispatcher\Event; + +class BroadcastEvent extends Event implements IBroadcastEvent { + + /** @var ABroadcastedEvent */ + private $event; + + public function __construct(ABroadcastedEvent $event) { + parent::__construct(); + + $this->event = $event; + } + + public function getName(): string { + return $this->event->broadcastAs(); + } + + public function getUids(): array { + return $this->event->getUids(); + } + + public function getPayload(): JsonSerializable { + return $this->event; + } + + public function setBroadcasted(): void { + $this->event->setBroadcasted(); + } + +} diff --git a/lib/private/EventDispatcher/EventDispatcher.php b/lib/private/EventDispatcher/EventDispatcher.php index 8830bae79d8..d9d7985f7cc 100644 --- a/lib/private/EventDispatcher/EventDispatcher.php +++ b/lib/private/EventDispatcher/EventDispatcher.php @@ -25,7 +25,10 @@ declare(strict_types=1); namespace OC\EventDispatcher; +use OC\Broadcast\Events\BroadcastEvent; +use OCP\Broadcast\Events\IBroadcastEvent; use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\ABroadcastedEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IContainer; use OCP\ILogger; @@ -73,6 +76,14 @@ class EventDispatcher implements IEventDispatcher { public function dispatch(string $eventName, Event $event): void { $this->dispatcher->dispatch($event, $eventName); + + if ($event instanceof ABroadcastedEvent && !$event->isPropagationStopped()) { + // Propagate broadcast + $this->dispatch( + IBroadcastEvent::class, + new BroadcastEvent($event) + ); + } } public function dispatchTyped(Event $event): void { |