Use MailerFactory in Mailer api
[MAILPOET-4115]
This commit is contained in:
committed by
Veljko V
parent
06fb13bd86
commit
6b758d90e6
@ -5,6 +5,7 @@ namespace MailPoet\API\JSON\v1;
|
||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||
use MailPoet\API\JSON\Error as APIError;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Mailer\MailerFactory;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Mailer\MetaInfo;
|
||||
use MailPoet\Services\AuthorizedEmailsController;
|
||||
@ -26,6 +27,9 @@ class Mailer extends APIEndpoint {
|
||||
/** @var MetaInfo */
|
||||
private $mailerMetaInfo;
|
||||
|
||||
/** @var MailerFactory */
|
||||
private $mailerFactory;
|
||||
|
||||
public $permissions = [
|
||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS,
|
||||
];
|
||||
@ -34,21 +38,22 @@ class Mailer extends APIEndpoint {
|
||||
AuthorizedEmailsController $authorizedEmailsController,
|
||||
SettingsController $settings,
|
||||
Bridge $bridge,
|
||||
MailerFactory $mailerFactory,
|
||||
MetaInfo $mailerMetaInfo
|
||||
) {
|
||||
$this->authorizedEmailsController = $authorizedEmailsController;
|
||||
$this->settings = $settings;
|
||||
$this->bridge = $bridge;
|
||||
$this->mailerFactory = $mailerFactory;
|
||||
$this->mailerMetaInfo = $mailerMetaInfo;
|
||||
}
|
||||
|
||||
public function send($data = []) {
|
||||
try {
|
||||
$mailer = new \MailPoet\Mailer\Mailer();
|
||||
$mailer->init(
|
||||
(isset($data['mailer'])) ? $data['mailer'] : false,
|
||||
(isset($data['sender'])) ? $data['sender'] : false,
|
||||
(isset($data['reply_to'])) ? $data['reply_to'] : false
|
||||
$mailer = $this->mailerFactory->buildMailer(
|
||||
(isset($data['mailer'])) ? $data['mailer'] : null,
|
||||
(isset($data['sender'])) ? $data['sender'] : null,
|
||||
(isset($data['reply_to'])) ? $data['reply_to'] : null
|
||||
);
|
||||
// report this as 'sending_test' in metadata since this endpoint is only used to test sending methods for now
|
||||
$extraParams = [
|
||||
|
@ -5,6 +5,7 @@ namespace MailPoet\Test\API\JSON\v1;
|
||||
use Codeception\Stub\Expected;
|
||||
use MailPoet\API\JSON\Response as APIResponse;
|
||||
use MailPoet\API\JSON\v1\Mailer;
|
||||
use MailPoet\Mailer\MailerFactory;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Mailer\MetaInfo;
|
||||
use MailPoet\Services\AuthorizedEmailsController;
|
||||
@ -23,7 +24,7 @@ class MailerTest extends \MailPoetTest {
|
||||
$authorizedEmailsController = $this->makeEmpty(AuthorizedEmailsController::class, ['checkAuthorizedEmailAddresses' => Expected::never()]);
|
||||
// resumeSending() method should clear the mailer log's status
|
||||
$bridge = new Bridge($settings);
|
||||
$mailerEndpoint = new Mailer($authorizedEmailsController, $settings, $bridge, new MetaInfo);
|
||||
$mailerEndpoint = new Mailer($authorizedEmailsController, $settings, $bridge, $this->diContainer->get(MailerFactory::class), new MetaInfo);
|
||||
$response = $mailerEndpoint->resumeSending();
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
$mailerLog = MailerLog::getMailerLog();
|
||||
@ -35,7 +36,7 @@ class MailerTest extends \MailPoetTest {
|
||||
$settings->set(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, ['invalid_sender_address' => 'a@b.c']);
|
||||
$authorizedEmailsController = $this->makeEmpty(AuthorizedEmailsController::class, ['checkAuthorizedEmailAddresses' => Expected::once()]);
|
||||
$bridge = new Bridge($settings);
|
||||
$mailerEndpoint = new Mailer($authorizedEmailsController, $settings, $bridge, new MetaInfo);
|
||||
$mailerEndpoint = new Mailer($authorizedEmailsController, $settings, $bridge, $this->diContainer->get(MailerFactory::class), new MetaInfo);
|
||||
$mailerEndpoint->resumeSending();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user