From e63202f7e42c59d8992f32567f61981fd064a6b2 Mon Sep 17 00:00:00 2001 From: Robin Richtsfeld Date: Fri, 16 Dec 2022 02:08:27 +0100 Subject: [PATCH] Pass WampRequest to registerPeriodicTimer --- docs/topics.md | 5 +++-- src/Server/App/Dispatcher/TopicDispatcher.php | 2 +- src/Topic/TopicPeriodicTimerInterface.php | 3 ++- tests/Server/App/Dispatcher/TopicDispatcherTest.php | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/topics.md b/docs/topics.md index ef2f63f2..b3d7c733 100644 --- a/docs/topics.md +++ b/docs/topics.md @@ -205,7 +205,7 @@ To implement an example fulfilling a scenario of "every 5 minutes all subscriber You will need to add these two methods to your Topic: -- `public function registerPeriodicTimer(Topic $topic): void` +- `public function registerPeriodicTimer(Topic $topic, WampRequest $request): void` - `public function setPeriodicTimer(TopicPeriodicTimer $periodicTimer): void` The `Gos\Bundle\WebSocketBundle\Topic\TopicPeriodicTimerTrait` is available to help implement the interface. @@ -215,6 +215,7 @@ The `Gos\Bundle\WebSocketBundle\Topic\TopicPeriodicTimerTrait` is available to h namespace App\Websocket\Topic; +use Gos\Bundle\WebSocketBundle\Router\WampRequest; use Gos\Bundle\WebSocketBundle\Topic\TopicPeriodicTimerInterface; use Gos\Bundle\WebSocketBundle\Topic\TopicPeriodicTimerTrait; use Ratchet\Wamp\Topic; @@ -223,7 +224,7 @@ class AcmePeriodicTopic extends AcmeTopic implements TopicPeriodicTimerInterface { use TopicPeriodicTimerTrait; - public function registerPeriodicTimer(Topic $topic): void + public function registerPeriodicTimer(Topic $topic, WampRequest $request): void { // Adds the periodic timer the first time a client connects to the topic $this->periodicTimer->addPeriodicTimer( diff --git a/src/Server/App/Dispatcher/TopicDispatcher.php b/src/Server/App/Dispatcher/TopicDispatcher.php index 0c855420..6c509ba8 100644 --- a/src/Server/App/Dispatcher/TopicDispatcher.php +++ b/src/Server/App/Dispatcher/TopicDispatcher.php @@ -204,7 +204,7 @@ public function dispatch( if (!$this->topicPeriodicTimer->isRegistered($appTopic) && 0 !== \count($topic)) { try { - $appTopic->registerPeriodicTimer($topic); + $appTopic->registerPeriodicTimer($topic, $request); } catch (\Throwable $e) { if (null !== $this->logger) { $this->logger->error( diff --git a/src/Topic/TopicPeriodicTimerInterface.php b/src/Topic/TopicPeriodicTimerInterface.php index 2b734cc5..77a5e725 100644 --- a/src/Topic/TopicPeriodicTimerInterface.php +++ b/src/Topic/TopicPeriodicTimerInterface.php @@ -2,11 +2,12 @@ namespace Gos\Bundle\WebSocketBundle\Topic; +use Gos\Bundle\WebSocketBundle\Router\WampRequest; use Ratchet\Wamp\Topic; interface TopicPeriodicTimerInterface { - public function registerPeriodicTimer(Topic $topic): void; + public function registerPeriodicTimer(Topic $topic, WampRequest $request): void; public function setPeriodicTimer(TopicPeriodicTimer $periodicTimer): void; } diff --git a/tests/Server/App/Dispatcher/TopicDispatcherTest.php b/tests/Server/App/Dispatcher/TopicDispatcherTest.php index ef9004af..aae8b9f5 100644 --- a/tests/Server/App/Dispatcher/TopicDispatcherTest.php +++ b/tests/Server/App/Dispatcher/TopicDispatcherTest.php @@ -432,7 +432,7 @@ public function getName(): string return 'topic.handler'; } - public function registerPeriodicTimer(Topic $topic): void + public function registerPeriodicTimer(Topic $topic, WampRequest $request): void { $this->registered = true; }