From 7b3071c14c62e699e484f7ff9fd722df1f5d393b Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sat, 29 Nov 2025 01:19:24 +0800 Subject: [PATCH 1/2] feat: add queue method to pending mail --- src/mail/src/Contracts/Mailable.php | 2 +- src/mail/src/Mailable.php | 4 ++-- src/mail/src/PendingMail.php | 25 ++++++++++++++++++++++ src/support/src/Testing/Fakes/MailFake.php | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/mail/src/Contracts/Mailable.php b/src/mail/src/Contracts/Mailable.php index fcc3fdc8b..0627f1492 100644 --- a/src/mail/src/Contracts/Mailable.php +++ b/src/mail/src/Contracts/Mailable.php @@ -49,5 +49,5 @@ public function locale(string $locale): static; /** * Set the name of the mailer that should be used to send the message. */ - public function mailer(string $mailer): static; + public function mailer(?string $mailer): static; } diff --git a/src/mail/src/Mailable.php b/src/mail/src/Mailable.php index b63f41c46..b44358322 100644 --- a/src/mail/src/Mailable.php +++ b/src/mail/src/Mailable.php @@ -143,7 +143,7 @@ class Mailable implements MailableContract, Renderable /** * The name of the mailer that should send the message. */ - public string $mailer = ''; + public ?string $mailer = null; /** * The rendered mailable views for testing / assertions. @@ -1470,7 +1470,7 @@ private function ensureAttachmentsAreHydrated(): void /** * Set the name of the mailer that should send the message. */ - public function mailer(string $mailer): static + public function mailer(?string $mailer): static { $this->mailer = $mailer; diff --git a/src/mail/src/PendingMail.php b/src/mail/src/PendingMail.php index 1034ed9bf..22dec82f7 100644 --- a/src/mail/src/PendingMail.php +++ b/src/mail/src/PendingMail.php @@ -4,6 +4,8 @@ namespace Hypervel\Mail; +use DateInterval; +use DateTimeInterface; use Hyperf\Conditionable\Conditionable; use Hypervel\Mail\Contracts\Mailable as MailableContract; use Hypervel\Mail\Contracts\Mailer as MailerContract; @@ -102,6 +104,29 @@ public function sendNow(MailableContract $mailable): ?SentMessage return $this->mailer->sendNow($this->fill($mailable)); } + /** + * Push the given mailable onto the queue. + */ + public function queue(MailableContract $mailable): mixed + { + /* @phpstan-ignore-next-line */ + return $this->mailer->queue( + $this->fill($mailable) + ); + } + + /** + * Deliver the queued message after (n) seconds. + */ + public function later(DateTimeInterface|DateInterval|int $delay, MailableContract $mailable): mixed + { + /* @phpstan-ignore-next-line */ + return $this->mailer->later( + $delay, + $this->fill($mailable) + ); + } + /** * Populate the mailable with the addresses. */ diff --git a/src/support/src/Testing/Fakes/MailFake.php b/src/support/src/Testing/Fakes/MailFake.php index 1bda03dcf..19052e1b9 100644 --- a/src/support/src/Testing/Fakes/MailFake.php +++ b/src/support/src/Testing/Fakes/MailFake.php @@ -460,7 +460,7 @@ public function later(DateInterval|DateTimeInterface|int $delay, array|Mailable| /** * Infer mailable class using reflection if a typehinted closure is passed to assertion. */ - protected function prepareMailableAndCallback(Closure|string $mailable, ?callable $callback): array + protected function prepareMailableAndCallback(Closure|string $mailable, callable|string|null $callback): array { if ($mailable instanceof Closure) { return [$this->firstClosureParameterType($mailable), $mailable]; From d666b58e37b5533fdbdd44a622af17c4b33b0240 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sat, 29 Nov 2025 01:55:46 +0800 Subject: [PATCH 2/2] chore: adjust code --- src/mail/src/PendingMail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mail/src/PendingMail.php b/src/mail/src/PendingMail.php index 22dec82f7..7781cf5ca 100644 --- a/src/mail/src/PendingMail.php +++ b/src/mail/src/PendingMail.php @@ -118,7 +118,7 @@ public function queue(MailableContract $mailable): mixed /** * Deliver the queued message after (n) seconds. */ - public function later(DateTimeInterface|DateInterval|int $delay, MailableContract $mailable): mixed + public function later(DateInterval|DateTimeInterface|int $delay, MailableContract $mailable): mixed { /* @phpstan-ignore-next-line */ return $this->mailer->later(