Refactor mailer blacklist from trait to DI [MAILPOET-2208]

This commit is contained in:
wxa
2019-07-17 13:07:57 +03:00
committed by M. Shull
parent 01bd3d036b
commit 160d3d0607
12 changed files with 52 additions and 36 deletions

View File

@ -3,14 +3,13 @@
namespace MailPoet\Mailer\Methods;
use MailPoet\Mailer\Mailer;
use MailPoet\Mailer\Methods\Common\BlacklistCheck;
use MailPoet\Mailer\Methods\ErrorMappers\SendGridMapper;
use MailPoet\WP\Functions as WPFunctions;
if (!defined('ABSPATH')) exit;
class SendGrid {
use BlacklistTrait;
public $url = 'https://api.sendgrid.com/api/mail.send.json';
public $api_key;
public $sender;
@ -19,6 +18,9 @@ class SendGrid {
/** @var SendGridMapper */
private $error_mapper;
/** @var BlacklistCheck */
private $blacklist;
private $wp;
function __construct($api_key, $sender, $reply_to, SendGridMapper $error_mapper) {
@ -27,10 +29,11 @@ class SendGrid {
$this->reply_to = $reply_to;
$this->error_mapper = $error_mapper;
$this->wp = new WPFunctions();
$this->blacklist = new BlacklistCheck();
}
function send($newsletter, $subscriber, $extra_params = []) {
if ($this->isBlacklisted($subscriber)) {
if ($this->blacklist->isBlacklisted($subscriber)) {
$error = $this->error_mapper->getBlacklistError($subscriber);
return Mailer::formatMailerErrorResult($error);
}