Skip to content

Commit

Permalink
Merge pull request #13 from weluse/NIOLAB-niolab
Browse files Browse the repository at this point in the history
Niolab niolab
  • Loading branch information
Julian-B90 authored Jun 19, 2019
2 parents 607571c + 0180d48 commit ec68afa
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 78 deletions.
55 changes: 22 additions & 33 deletions Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

class Mailer extends BaseMailer
{

private $_mailjet;

private $_apikey;
Expand All @@ -41,20 +40,19 @@ class Mailer extends BaseMailer
'unsub',
];

/**
* @var string message default class name.
*/
/**
* @var string message default class name.
*/
public $messageClass = 'weluse\mailjet\Message';

/**
* readonly
* @var $_response Mailjet\Response
*/
/**
* readonly
* @var $_response Mailjet\Response
*/
private $_response;

public function init()
{

if (!$this->_apikey) {
throw new InvalidConfigException(sprintf('"%s::apikey" cannot be null.', get_class($this)));
}
Expand All @@ -77,19 +75,17 @@ public function init()
* @param string $secret
* @throws InvalidConfigException
*/
public function setSecret($secret)
{

if (!is_string($secret)) {
throw new InvalidConfigException(sprintf('"%s::secret" should be a string, "%s" given.', get_class($this), gettype($apikey)));
}
$trimmedSecret = trim($secret);
if (!strlen($trimmedSecret) > 0) {
throw new InvalidConfigException(sprintf('"%s::secret" length should be greater than 0.', get_class($this)));
}
$this->_secret = $trimmedSecret;

}
public function setSecret($secret)
{
if (!is_string($secret)) {
throw new InvalidConfigException(sprintf('"%s::secret" should be a string, "%s" given.', get_class($this), gettype($apikey)));
}
$trimmedSecret = trim($secret);
if (!strlen($trimmedSecret) > 0) {
throw new InvalidConfigException(sprintf('"%s::secret" length should be greater than 0.', get_class($this)));
}
$this->_secret = $trimmedSecret;
}

/**
* Sets the API key for Mailjet
Expand All @@ -114,7 +110,6 @@ public function setApikey($apikey)
*/
public function createMailjet()
{

$mj = new \Mailjet\Client($this->_apikey, $this->_secret);

$this->_mailjet = $mj;
Expand All @@ -130,7 +125,6 @@ public function getResponse()
*/
protected function sendMessage($message)
{

$to = $cc = $bcc = [];

foreach ($message->to as $email => $name) {
Expand All @@ -149,7 +143,6 @@ protected function sendMessage($message)
$cc[] = $address;
}


foreach ($message->bcc as $email => $name) {
$address = '<' . $email . '>';
if (!empty($name)) {
Expand All @@ -158,16 +151,15 @@ protected function sendMessage($message)
$bcc[] = $address;
}


$body = [
'Subject' => $message->subject,
'Text-part' => $message->textBody,
'Html-part' => $message->htmlBody,
'To' => join(', ',$to),
'To' => join(', ', $to),
];

if ($cc) {
$body['Cc'] = join(', ',$cc);
$body['Cc'] = join(', ', $cc);
}
if ($bcc) {
$body['Bcc'] = join(', ', $bcc);
Expand All @@ -181,7 +173,7 @@ protected function sendMessage($message)
}

//Adds Reply-To to header
if(!empty($message->replyTo)) {
if (!empty($message->replyTo)) {
$body['Headers']['Reply-to'] = $message->replyTo;
}

Expand All @@ -194,7 +186,6 @@ protected function sendMessage($message)

public function setTracking($tracking)
{

if (is_array($tracking)) {

$urlValidator = new UrlValidator;
Expand All @@ -212,7 +203,6 @@ public function setTracking($tracking)
throw new InvalidConfigException(sprintf('the %s event is not supported', $event));
}
}

} else {
throw new InvalidConfigException('The trackingActions must be an array');
}
Expand Down Expand Up @@ -270,7 +260,6 @@ public function clearTracking($event)
$eventCallbackurl = Resources::$Eventcallbackurl;
$eventCallbackurl[1] = $event;

$response = $this->_mailjet->delete($eventCallbackurl);
$this->_mailjet->delete($eventCallbackurl);
}

}
Loading

0 comments on commit ec68afa

Please sign in to comment.