From c4b742ac0d6ca14bb86597a987826fa55c500882 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 9 Sep 2024 20:52:37 +1200 Subject: [PATCH] Allow overriding realtime instance --- app/realtime.php | 15 +++++++++++---- src/Appwrite/Messaging/Adapter/Realtime.php | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index b8fdb2cf21..11bcf923ef 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -40,7 +40,7 @@ require_once __DIR__ . '/init.php'; Runtime::enableCoroutine(SWOOLE_HOOK_ALL); // Allows overriding -if (!function_exists("getConsoleDB")) { +if (!function_exists('getConsoleDB')) { function getConsoleDB(): Database { global $register; @@ -66,7 +66,7 @@ if (!function_exists("getConsoleDB")) { } // Allows overriding -if (!function_exists("getProjectDB")) { +if (!function_exists('getProjectDB')) { function getProjectDB(Document $project): Database { global $register; @@ -113,7 +113,7 @@ if (!function_exists("getProjectDB")) { } // Allows overriding -if (!function_exists("getCache")) { +if (!function_exists('getCache')) { function getCache(): Cache { global $register; @@ -135,7 +135,14 @@ if (!function_exists("getCache")) { } } -$realtime = new Realtime(); +if (!function_exists('getRealtime')) { + function getRealtime(): Realtime + { + return new Realtime(); + } +} + +$realtime = getRealtime(); /** * Table for statistics across all workers. diff --git a/src/Appwrite/Messaging/Adapter/Realtime.php b/src/Appwrite/Messaging/Adapter/Realtime.php index 55d8db2924..49aa305c3f 100644 --- a/src/Appwrite/Messaging/Adapter/Realtime.php +++ b/src/Appwrite/Messaging/Adapter/Realtime.php @@ -243,7 +243,11 @@ class Realtime extends Adapter * @param string $event * @param Document $payload * @param Document|null $project + * @param Document|null $database + * @param Document|null $collection + * @param Document|null $bucket * @return array + * @throws \Exception */ public static function fromPayload(string $event, Document $payload, Document $project = null, Document $database = null, Document $collection = null, Document $bucket = null): array {