MessageWrapper.php in Sparkpost email 8.2
File
src/MessageWrapper.php
View source
<?php
namespace Drupal\sparkpost;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use SparkPost\SparkPostException;
class MessageWrapper implements MessageWrapperInterface {
use DependencySerializationTrait;
protected $sparkpostMessage;
protected $drupalMessage;
protected $apiResponseException;
protected $result;
protected $clientService;
public function __construct(ClientServiceInterface $clientService) {
$this->clientService = $clientService;
}
public function setDrupalMessage(array $drupal_message) {
$this->drupalMessage = $drupal_message;
}
public function setSparkpostMessage(array $sparkpost_message) {
$this->sparkpostMessage = $sparkpost_message;
}
public function setApiResponseException(SparkPostException $sparkPostException) {
$this->apiResponseException = $sparkPostException;
}
public function setResult(array $result) {
$this->result = $result;
}
public function getSparkpostMessage() {
return $this->sparkpostMessage;
}
public function getDrupalMessage() {
return $this->drupalMessage;
}
public function getApiResponseException() {
return $this->apiResponseException;
}
public function getResult() {
return $this->result;
}
public function getClientService() {
return $this->clientService;
}
public function sendMessage() {
try {
$data = $this->clientService
->sendMessage($this->sparkpostMessage);
$this
->setResult($data);
\Drupal::moduleHandler()
->invokeAll('sparkpost_mailsend_success', [
$this,
]);
return TRUE;
} catch (SparkPostException $e) {
$this
->setApiResponseException($e);
} catch (\Exception $e) {
}
\Drupal::moduleHandler()
->invokeAll('sparkpost_mailsend_error', [
$this,
]);
return FALSE;
}
public function clearApiResposeException() {
$this->apiResponseException = NULL;
}
}