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,
+ );
+ }
+
/**
* 发送邮件
*