You are here

private function MandrillAPI::getAPIObject in Mandrill 8

Return Mandrill API object for communication with the mandrill server.

Parameters

bool $reset: Pass in TRUE to reset the statically cached object.

Return value

\Mandrill|bool Mandrill Object upon success FALSE if 'mandrill_api_key' is unset

22 calls to MandrillAPI::getAPIObject()
MandrillAPI::addInboundDomain in src/MandrillAPI.php
Creates a new inbound domain.
MandrillAPI::addInboundRoute in src/MandrillAPI.php
Adds a new inbound route for a domain.
MandrillAPI::addWebhook in src/MandrillAPI.php
Creates a new webhook.
MandrillAPI::deleteInboundDomain in src/MandrillAPI.php
Deletes an inbound domain.
MandrillAPI::getInboundDomains in src/MandrillAPI.php
Gets a list of inbound domains.

... See full list

File

src/MandrillAPI.php, line 509

Class

MandrillAPI
Service class to integrate with Mandrill.

Namespace

Drupal\mandrill

Code

private function getAPIObject($reset = FALSE) {
  $api =& drupal_static(__FUNCTION__, NULL);
  if ($api === NULL || $reset) {
    if (!$this
      ->isLibraryInstalled()) {
      $msg = t('Failed to load Mandrill PHP library. Please refer to the installation requirements.');
      $this->log
        ->error($msg);
      \Drupal::messenger()
        ->addError($msg);
      return NULL;
    }
    $api_key = $this->config
      ->get('mandrill_api_key');
    $api_timeout = $this->config
      ->get('mandrill_api_timeout');
    if (empty($api_key)) {
      $msg = t('Failed to load Mandrill API Key. Please check your Mandrill settings.');
      $this->log
        ->error($msg);
      \Drupal::messenger()
        ->addError($msg);
      return FALSE;
    }

    // We allow the class name to be overridden, following the example of core's
    // mailsystem, in order to use alternate Mandrill classes.
    $className = $this->config
      ->get('mandrill_api_classname');
    $api = new $className($api_key, $api_timeout);
  }
  return $api;
}