Commit a45d8a7a authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Adaptation au MailerService

parent 322b9b50
Pipeline #4434 failed with stages
in 2 minutes and 24 seconds
......@@ -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;
}
......
......@@ -2,6 +2,7 @@
namespace UnicaenApp\Mouchard;
use UnicaenApp\Service\Mailer\MailerService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
......@@ -26,6 +27,10 @@ class MouchardSenderMailFactory implements FactoryInterface
$mouchardSenderMail->setModuleOptions($unicaenAppOptions);
}
/** @var MailerService $mailerService */
$mailerService = $serviceLocator->get(MailerService::class);
$mouchardSenderMail->setMailerService($mailerService);
return $mouchardSenderMail;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment