Skip to content
Snippets Groups Projects

Adaptation au MailerService

Merged Laurent Lecluse requested to merge mouchard2 into master
2 files
+ 16
26
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,6 +5,7 @@ namespace UnicaenApp\Mouchard;
use UnicaenApp\Controller\Plugin\Mail;
use UnicaenApp\Options\ModuleOptions;
use UnicaenApp\Options\Traits\ModuleOptionsAwareTrait;
use UnicaenApp\Service\Mailer\MailerServiceAwareTrait;
use Zend\Mail\Message;
use Zend\Mime\Mime;
use Zend\Mime\Message as MimeMessage;
@@ -22,16 +23,12 @@ use Zend\ServiceManager\Exception\InvalidArgumentException;
class MouchardSenderMail implements MouchardSenderInterface
{
use ModuleOptionsAwareTrait;
/**
* @var Mail
*/
private $mail;
use MailerServiceAwareTrait;
/**
* @var string
*/
private $from = 'ne-pas-repondre@unicaen.fr';
private $from;
/**
* @var string || string[]
@@ -50,7 +47,7 @@ class MouchardSenderMail implements MouchardSenderInterface
$mail->setFrom($this->getFrom());
$mail->setTo($this->getTo());
$mail->setSubject($this->makeTruncSubject($message->getAlias()) . ' ' . $message->getSubject());
$this->getMail()->send($mail);
$this->mailerService->send($mail);
return $this;
}
@@ -101,30 +98,18 @@ class MouchardSenderMail implements MouchardSenderInterface
protected function getMail()
{
if (!$this->mail && $this->getModuleOptions()) {
$mailOptions = $this->getModuleOptions()->getMail();
if (!isset($mailOptions['transport_options'])) {
throw new InvalidArgumentException("Options de transport de mail introuvables.");
}
$transport = new Smtp(new SmtpOptions($mailOptions['transport_options']));
$this->mail = new Mail($transport);
}
return $this->mail;
}
/**
* @return string
*/
public function getFrom()
{
if (!$this->from){
$mailOptions = $this->getModuleOptions()->mail;
if (isset($mailOptions['from'])){
return $mailOptions['from'];
}
}
return $this->from;
}
Loading