Move inline function to a private method

[MAILPOET-2333]
This commit is contained in:
Amine Ben hammou
2019-09-12 21:32:45 +01:00
committed by Jack Kitterhing
parent e48ad229e1
commit e9d12fb40e

View File

@ -90,45 +90,17 @@ class MailPoet {
}
function getBody($newsletter, $subscriber, $extra_params = []) {
$_this = $this;
$composeBody = function($newsletter, $subscriber, $unsubscribe_url) use($_this) {
$body = [
'to' => ([
'address' => $subscriber['email'],
'name' => $subscriber['name'],
]),
'from' => ([
'address' => $_this->sender['from_email'],
'name' => $_this->sender['from_name'],
]),
'reply_to' => ([
'address' => $_this->reply_to['reply_to_email'],
'name' => $_this->reply_to['reply_to_name'],
]),
'subject' => $newsletter['subject'],
];
if (!empty($newsletter['body']['html'])) {
$body['html'] = $newsletter['body']['html'];
}
if (!empty($newsletter['body']['text'])) {
$body['text'] = $newsletter['body']['text'];
}
if ($unsubscribe_url) {
$body['list_unsubscribe'] = $unsubscribe_url;
}
return $body;
};
if (is_array($newsletter) && is_array($subscriber)) {
$body = [];
for ($record = 0; $record < count($newsletter); $record++) {
$body[] = $composeBody(
$body[] = $this->composeBody(
$newsletter[$record],
$this->processSubscriber($subscriber[$record]),
(!empty($extra_params['unsubscribe_url'][$record])) ? $extra_params['unsubscribe_url'][$record] : false
);
}
} else {
$body[] = $composeBody(
$body[] = $this->composeBody(
$newsletter,
$this->processSubscriber($subscriber),
(!empty($extra_params['unsubscribe_url'])) ? $extra_params['unsubscribe_url'] : false
@ -136,4 +108,32 @@ class MailPoet {
}
return $body;
}
private function composeBody($newsletter, $subscriber, $unsubscribe_url) {
$body = [
'to' => ([
'address' => $subscriber['email'],
'name' => $subscriber['name'],
]),
'from' => ([
'address' => $this->sender['from_email'],
'name' => $this->sender['from_name'],
]),
'reply_to' => ([
'address' => $this->reply_to['reply_to_email'],
'name' => $this->reply_to['reply_to_name'],
]),
'subject' => $newsletter['subject'],
];
if (!empty($newsletter['body']['html'])) {
$body['html'] = $newsletter['body']['html'];
}
if (!empty($newsletter['body']['text'])) {
$body['text'] = $newsletter['body']['text'];
}
if ($unsubscribe_url) {
$body['list_unsubscribe'] = $unsubscribe_url;
}
return $body;
}
}