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; 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(); } /**