From bebac5992a89ebe41eb20ea926938f4b3fde2cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=9C=E4=BA=91?= Date: Thu, 12 Sep 2024 19:06:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(email):=20=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=AE=9A=E5=88=B6=E5=8F=91=E4=BB=B6=E4=BA=BA?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李东云 --- .idea/HDK-Core.iml | 1 - .idea/php.xml | 58 -------------------------- src/Events/EmailWillSent.php | 11 ++++- src/Listener/EmailWillSentListener.php | 5 ++- src/Service/EmailService.php | 12 ++++++ 5 files changed, 25 insertions(+), 62 deletions(-) diff --git a/.idea/HDK-Core.iml b/.idea/HDK-Core.iml index 1aa62b7..61906b9 100644 --- a/.idea/HDK-Core.iml +++ b/.idea/HDK-Core.iml @@ -91,7 +91,6 @@ - diff --git a/.idea/php.xml b/.idea/php.xml index 9a6f168..209769e 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -107,7 +107,6 @@ - @@ -154,46 +153,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -203,27 +166,6 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Events/EmailWillSent.php b/src/Events/EmailWillSent.php index 2199075..82c1c29 100644 --- a/src/Events/EmailWillSent.php +++ b/src/Events/EmailWillSent.php @@ -9,6 +9,8 @@ namespace Singularity\HDK\Core\Events; +use Singularity\HDK\Core\Service\EmailService; + /** * Singularity\HDK\Core\Events\EmailWillSent@HDK-Core * @@ -51,6 +53,11 @@ class EmailWillSent */ public string $type = 'text'; + /** + * @var EmailService|null + */ + public ?EmailService $sender; + public function __construct( /** @@ -64,7 +71,8 @@ class EmailWillSent */ array $cc = [], string $type = 'text', - array $bcc = [] + array $bcc = [], + ?EmailService $sender = null ) { $this->type = $type; $this->cc = $cc; @@ -72,5 +80,6 @@ class EmailWillSent $this->subject = $subject; $this->target = $target; $this->bcc = $bcc; + $this->sender = $sender; } } diff --git a/src/Listener/EmailWillSentListener.php b/src/Listener/EmailWillSentListener.php index 9c2419b..bd344e6 100644 --- a/src/Listener/EmailWillSentListener.php +++ b/src/Listener/EmailWillSentListener.php @@ -48,9 +48,10 @@ class EmailWillSentListener extends AbstractListener public function process(object $event): void { $stdoutLogger = $this->container->get(StdoutLoggerInterface::class); - $emailService = $this->container->get(EmailService::class); + + /** @var $event EmailWillSent */ + $emailService = $event->sender ?? EmailService::make(); try { - /** @var $event EmailWillSent */ $event->type === 'html' ? $emailService->sendHtml( $event->target, diff --git a/src/Service/EmailService.php b/src/Service/EmailService.php index 7ef5279..b41b6e2 100644 --- a/src/Service/EmailService.php +++ b/src/Service/EmailService.php @@ -42,6 +42,18 @@ class EmailService ); } + public static function make( + ?string $dsn = null, + ?string $mailSenderName = null, + ?string $mailSender = null + ): EmailService { + return new static( + $dsn, + $mailSenderName, + $mailSender, + ); + } + /** * 发送邮件 *