Skip to content

Commit

Permalink
- Update comment save mail
Browse files Browse the repository at this point in the history
- Move MailerSenderEmptyException before to save mails
  • Loading branch information
Kevin Gay authored and FabienPapet committed May 22, 2018
1 parent 7c53972 commit 4ec696f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Provider/Mail/DoctrineMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 0 additions & 5 deletions Services/MailBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Extellient\MailBundle\Services;

use Extellient\MailBundle\Entity\Mail;
use Extellient\MailBundle\Exception\MailerSenderEmptyException;

/**
* Class MailBuilder
Expand Down Expand Up @@ -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)) {
Expand Down
5 changes: 3 additions & 2 deletions Services/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Extellient\MailBundle\Services;

use Extellient\MailBundle\Entity\Mail;
use Extellient\MailBundle\Entity\MailInterface;
use Extellient\MailBundle\Provider\Mail\MailProviderInterface;

/**
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 4ec696f

Please sign in to comment.