From 4ec696f20b96864fca4d90a842637e017d66d8aa Mon Sep 17 00:00:00 2001 From: Kevin Gay Date: Fri, 18 May 2018 11:43:06 +0200 Subject: [PATCH] - Update comment save mail - Move MailerSenderEmptyException before to save mails --- Provider/Mail/DoctrineMailProvider.php | 6 ++++++ Services/MailBuilder.php | 5 ----- Services/Mailer.php | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Provider/Mail/DoctrineMailProvider.php b/Provider/Mail/DoctrineMailProvider.php index 56d73c2..2291283 100644 --- a/Provider/Mail/DoctrineMailProvider.php +++ b/Provider/Mail/DoctrineMailProvider.php @@ -5,6 +5,7 @@ use Doctrine\ORM\EntityManagerInterface; use Extellient\MailBundle\Entity\Mail; use Extellient\MailBundle\Entity\MailInterface; +use Extellient\MailBundle\Exception\MailerSenderEmptyException; /** * Class MailProviderDoctrine. @@ -38,7 +39,12 @@ public function save($mails) } //Persist all mails + /** @var MailInterface $mail */ foreach ($mails as $mail) { + if (empty($mail->getSenderEmail())) { + throw new MailerSenderEmptyException($mail); + } + $this->entityManager->persist($mail); } diff --git a/Services/MailBuilder.php b/Services/MailBuilder.php index 1aa1150..e73c89d 100644 --- a/Services/MailBuilder.php +++ b/Services/MailBuilder.php @@ -4,7 +4,6 @@ namespace Extellient\MailBundle\Services; use Extellient\MailBundle\Entity\Mail; -use Extellient\MailBundle\Exception\MailerSenderEmptyException; /** * Class MailBuilder @@ -47,10 +46,6 @@ public function createEmail($subject, $body, $recipients, $attachements = []) $mail = new Mail($subject, $body, $recipients); - if (empty($this->mailAddressFrom)) { - throw new MailerSenderEmptyException($mail); - } - $mail->setSenderEmail($this->mailAddressFrom); if (!empty($this->mailAliasFrom)) { diff --git a/Services/Mailer.php b/Services/Mailer.php index 2f8526c..f5e2f21 100644 --- a/Services/Mailer.php +++ b/Services/Mailer.php @@ -3,6 +3,7 @@ namespace Extellient\MailBundle\Services; use Extellient\MailBundle\Entity\Mail; +use Extellient\MailBundle\Entity\MailInterface; use Extellient\MailBundle\Provider\Mail\MailProviderInterface; /** @@ -47,9 +48,9 @@ public function createEmail($subject, $body, $recipients, $attachements = []) } /** - * Flush the Mail. + * Save mails. * - * @param $mails + * @param MailInterface|MailInterface[] $mails */ public function save($mails) {