From c7fd31285d0f9eba27f416c5afe739bfd85c2c41 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 16 Dec 2025 10:36:45 +0530 Subject: [PATCH] chore: lazy init sms adapter + late static binding --- src/Appwrite/Event/Database.php | 2 +- src/Appwrite/Event/Event.php | 28 ++++++++++----------- src/Appwrite/Event/Messaging.php | 13 ---------- src/Appwrite/Platform/Workers/Messaging.php | 7 +++--- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/Appwrite/Event/Database.php b/src/Appwrite/Event/Database.php index 8e7f6b7625..eac30ac07e 100644 --- a/src/Appwrite/Event/Database.php +++ b/src/Appwrite/Event/Database.php @@ -161,7 +161,7 @@ class Database extends Event return $this->document; } - public function setProject(Document $project): self + public function setProject(Document $project): static { $database = $project->getAttribute('database'); if (!empty($database)) { diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index f8fb012075..c7bb22f715 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -92,9 +92,9 @@ class Event * Set queue used for this event. * * @param string $queue - * @return Event + * @return static */ - public function setQueue(string $queue): self + public function setQueue(string $queue): static { $this->queue = $queue; @@ -114,9 +114,9 @@ class Event /** * Set event name used for this event. * @param string $event - * @return Event + * @return static */ - public function setEvent(string $event): self + public function setEvent(string $event): static { $this->event = $event; @@ -137,9 +137,9 @@ class Event * Set project for this event. * * @param Document $project - * @return self + * @return static */ - public function setProject(Document $project): self + public function setProject(Document $project): static { $this->project = $project; return $this; @@ -159,9 +159,9 @@ class Event * Set platform for this event. * * @param array $platform - * @return self + * @return static */ - public function setPlatform(array $platform): self + public function setPlatform(array $platform): static { $this->platform = $platform; return $this; @@ -181,9 +181,9 @@ class Event * Set user for this event. * * @param Document $user - * @return self + * @return static */ - public function setUser(Document $user): self + public function setUser(Document $user): static { $this->user = $user; @@ -193,9 +193,9 @@ class Event /** * Set user ID for this event. * - * @return self + * @return static */ - public function setUserId(string $userId): self + public function setUserId(string $userId): static { $this->userId = $userId; @@ -225,9 +225,9 @@ class Event * * @param array $payload * @param array $sensitive - * @return self + * @return static */ - public function setPayload(array $payload, array $sensitive = []): self + public function setPayload(array $payload, array $sensitive = []): static { $this->payload = $payload; diff --git a/src/Appwrite/Event/Messaging.php b/src/Appwrite/Event/Messaging.php index 3ddbac1040..f4c72c7d72 100644 --- a/src/Appwrite/Event/Messaging.php +++ b/src/Appwrite/Event/Messaging.php @@ -161,19 +161,6 @@ class Messaging extends Event return $this->scheduledAt; } - /** - * Set project for this event. - * - * @param Document $project - * @return self - */ - public function setProject(Document $project): self - { - $this->project = $project; - - return $this; - } - /** * Prepare the payload for the event * diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 64224a9770..ae94c7580d 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -62,9 +62,6 @@ class Messaging extends Action */ public function __construct() { - - $this->adapter = $this->createInternalSMSAdapter(); - $this ->desc('Messaging worker') ->inject('message') @@ -390,6 +387,10 @@ class Messaging extends Action private function sendInternalSMSMessage(Document $message, Document $project, array $recipients, Log $log): void { + if ($this->adapter === null) { + $this->adapter = $this->createInternalSMSAdapter(); + } + if ($this->adapter === null) { Console::warning('Skipped SMS processing. SMS adapter is not set.'); return;