You are here

class MessageWrapper in Sparkpost email 8.2

Message wrapper class.

Hierarchy

Expanded class hierarchy of MessageWrapper

1 file declares its use of MessageWrapper
QueuedMessageWrapper.php in modules/sparkpost_requeue/src/QueuedMessageWrapper.php
1 string reference to 'MessageWrapper'
sparkpost.services.yml in ./sparkpost.services.yml
sparkpost.services.yml
1 service uses MessageWrapper
sparkpost.message_wrapper in ./sparkpost.services.yml
Drupal\sparkpost\MessageWrapper

File

src/MessageWrapper.php, line 11

Namespace

Drupal\sparkpost
View source
class MessageWrapper implements MessageWrapperInterface {
  use DependencySerializationTrait;

  /**
   * The sparkpost message.
   *
   * @var array
   */
  protected $sparkpostMessage;

  /**
   * The Drupal message.
   *
   * @var array
   */
  protected $drupalMessage;

  /**
   * Exception, if any.
   *
   * @var \SparkPost\SparkPostException
   */
  protected $apiResponseException;

  /**
   * Result, if any.
   *
   * @var array
   */
  protected $result;

  /**
   * Client to use.
   *
   * @var \Drupal\sparkpost\ClientServiceInterface
   */
  protected $clientService;

  /**
   * SparkpostMessage constructor.
   */
  public function __construct(ClientServiceInterface $clientService) {
    $this->clientService = $clientService;
  }

  /**
   * {@inheritdoc}
   */
  public function setDrupalMessage(array $drupal_message) {
    $this->drupalMessage = $drupal_message;
  }

  /**
   * {@inheritdoc}
   */
  public function setSparkpostMessage(array $sparkpost_message) {
    $this->sparkpostMessage = $sparkpost_message;
  }

  /**
   * {@inheritdoc}
   */
  public function setApiResponseException(SparkPostException $sparkPostException) {
    $this->apiResponseException = $sparkPostException;
  }

  /**
   * {@inheritdoc}
   */
  public function setResult(array $result) {
    $this->result = $result;
  }

  /**
   * {@inheritdoc}
   */
  public function getSparkpostMessage() {
    return $this->sparkpostMessage;
  }

  /**
   * {@inheritdoc}
   */
  public function getDrupalMessage() {
    return $this->drupalMessage;
  }

  /**
   * {@inheritdoc}
   */
  public function getApiResponseException() {
    return $this->apiResponseException;
  }

  /**
   * {@inheritdoc}
   */
  public function getResult() {
    return $this->result;
  }

  /**
   * {@inheritdoc}
   */
  public function getClientService() {
    return $this->clientService;
  }

  /**
   * {@inheritdoc}
   */
  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) {

      // @todo Handle sparkpost exceptions separately.
    }
    \Drupal::moduleHandler()
      ->invokeAll('sparkpost_mailsend_error', [
      $this,
    ]);
    return FALSE;
  }

  /**
   * Clears the API response exception.
   */
  public function clearApiResposeException() {
    $this->apiResponseException = NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessageWrapper::$apiResponseException protected property Exception, if any.
MessageWrapper::$clientService protected property Client to use. 1
MessageWrapper::$drupalMessage protected property The Drupal message.
MessageWrapper::$result protected property Result, if any.
MessageWrapper::$sparkpostMessage protected property The sparkpost message.
MessageWrapper::clearApiResposeException public function Clears the API response exception. Overrides MessageWrapperInterface::clearApiResposeException
MessageWrapper::getApiResponseException public function Gets the last exception thrown. Overrides MessageWrapperInterface::getApiResponseException
MessageWrapper::getClientService public function Gets the client service. Overrides MessageWrapperInterface::getClientService
MessageWrapper::getDrupalMessage public function Gets the Drupal message the sparkpost message was based on. Overrides MessageWrapperInterface::getDrupalMessage
MessageWrapper::getResult public function Gets the last result. Overrides MessageWrapperInterface::getResult
MessageWrapper::getSparkpostMessage public function Gets the sparkpost message to send. Overrides MessageWrapperInterface::getSparkpostMessage
MessageWrapper::sendMessage public function Sends the message. Overrides MessageWrapperInterface::sendMessage
MessageWrapper::setApiResponseException public function Sets the API response exception. Overrides MessageWrapperInterface::setApiResponseException
MessageWrapper::setDrupalMessage public function Sets the Drupal message. Overrides MessageWrapperInterface::setDrupalMessage
MessageWrapper::setResult public function Sets the result from the API call. Overrides MessageWrapperInterface::setResult
MessageWrapper::setSparkpostMessage public function Sets the sparkpost message. Overrides MessageWrapperInterface::setSparkpostMessage
MessageWrapper::__construct public function SparkpostMessage constructor. Overrides MessageWrapperInterface::__construct 1