From 686964981a49cfadef495061d72927a19e7c6fd2 Mon Sep 17 00:00:00 2001 From: vmikhav Date: Tue, 15 Mar 2022 10:11:51 +0200 Subject: [PATCH 1/2] allow to define custom transports --- publish/mail.php | 1 - src/MailManager.php | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/publish/mail.php b/publish/mail.php index 57b54b0..b45e0a1 100644 --- a/publish/mail.php +++ b/publish/mail.php @@ -75,7 +75,6 @@ ], 'log' => [ - 'dsn' => 'log://', 'transport' => \HyperfExt\Mail\Transport\LogTransport::class, 'options' => [ 'name' => 'mail.local', diff --git a/src/MailManager.php b/src/MailManager.php index 374140c..6d83a1c 100644 --- a/src/MailManager.php +++ b/src/MailManager.php @@ -99,12 +99,12 @@ public function send(MailableInterface $mailable): void */ protected function createTransport(array $config): TransportInterface { - if (empty($config['dsn'])) { - throw new InvalidArgumentException('The mail transport DSN must be specified.'); + if (!empty($config['transport'])) { + return make($config['transport'], ['options' => $config['options'] ?? []]); } - if ($config['dsn'] === 'log://') { - return make($config['transport'], ['options' => $config['options'] ?? []]); + if (empty($config['dsn'])) { + throw new InvalidArgumentException('The mail transport DSN must be specified.'); } $logger = null; From 8c3d5abc51a321e2359a826d2d65e7afddba157d Mon Sep 17 00:00:00 2001 From: vmikhav Date: Thu, 17 Mar 2022 12:22:10 +0200 Subject: [PATCH 2/2] fix rendering empty email if view is not cached --- src/Mailable.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Mailable.php b/src/Mailable.php index 2488d54..b9b7e5c 100644 --- a/src/Mailable.php +++ b/src/Mailable.php @@ -493,7 +493,8 @@ protected function hasRecipient( protected function buildView(array $data): array { - Coroutine::create(function () use ($data, &$html, &$plain) { + $chan = new \Swoole\Coroutine\Channel(1); + Coroutine::create(function () use ($data, $chan) { if (! empty($this->locale)) { ApplicationContext::getContainer()->get(TranslatorInterface::class)->setLocale($this->locale); } @@ -511,9 +512,11 @@ protected function buildView(array $data): array } elseif (! empty($this->textViewTemplate)) { $plain = $this->renderView($this->textViewTemplate, $data); } + + $chan->push([$html, $plain]); }); - return [$html, $plain]; + return $chan->pop(); } /**