You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 line
883B

  1. <?php
  2. namespace common\components\BulkMailer;
  3. use domain\Communication\Email\Email;
  4. use domain\Setting\AdminSettingBag;
  5. use yii\base\ErrorException;
  6. class BulkMailerProxy implements BulkMailerInterface
  7. {
  8. public function getBulkMailer(): BulkMailerInterface
  9. {
  10. $bulkMailerSetting = AdminSettingBag::getInstance()->get('bulkMailer');
  11. if($bulkMailerSetting == BulkMailerInterface::MAILJET) {
  12. return new BulkMailerMailjet();
  13. }
  14. elseif($bulkMailerSetting == BulkMailerInterface::BREVO) {
  15. return new BulkMailerBrevo();
  16. }
  17. else {
  18. throw new ErrorException("Le mailer pour les emails en masse n'est pas défini dans les paramètres admin.");
  19. }
  20. }
  21. public function sendEmail(Email $email, array $usersArray)
  22. {
  23. $this->getBulkMailer()->sendEmail($email, $usersArray);
  24. }
  25. }