You are here

class MandrillTestService in Mandrill 8

Test Mandrill service.

Hierarchy

Expanded class hierarchy of MandrillTestService

1 string reference to 'MandrillTestService'
mandrill.services.yml in ./mandrill.services.yml
mandrill.services.yml
1 service uses MandrillTestService
mandrill.test.service in ./mandrill.services.yml
Drupal\mandrill\MandrillTestService

File

src/MandrillTestService.php, line 8

Namespace

Drupal\mandrill
View source
class MandrillTestService extends MandrillService {

  /**
   * {@inheritdoc}
   */
  protected function handleSendResponse($response, $message) {
    if (isset($response['status'])) {

      // There was a problem sending the message.
      return FALSE;
    }
    foreach ($response as $result) {

      // Allow other modules to react based on a send result.
      \Drupal::moduleHandler()
        ->invokeAll('mandrill_mailsend_result', [
        $result,
      ], [
        $message,
      ]);
      switch ($result['status']) {
        case "error":
        case "invalid":
        case "rejected":
          return FALSE;
      }
    }
    return TRUE;
  }

  /**
   * Abstracts sending of messages using PHP's built-in mail() function
   * instead of Mandrill's sending API.
   *
   * @param array $message
   *   A message array formatted for Mandrill's sending API.
   *
   * @return bool
   *   TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
   */
  public function send($message) {
    if (\Drupal::config('system.mail')
      ->get('interface.default') === 'test_mail_collector') {
      $captured_emails = \Drupal::state()
        ->get('system.test_mail_collector') ?: [];
      $captured_emails[] = $message;
      \Drupal::state()
        ->set('system.test_mail_collector', $captured_emails);
      return TRUE;
    }
    return parent::send($message);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MandrillService::$config protected property The Config Factory service.
MandrillService::$log protected property The Logger Factory service.
MandrillService::$mandrill_api protected property The Mandrill API service.
MandrillService::getMailSystems public function Get the mail systems defined in the mail system module. Overrides MandrillServiceInterface::getMailSystems
MandrillService::getReceivers public function Helper to generate an array of recipients. Overrides MandrillServiceInterface::getReceivers
MandrillService::__construct public function Constructs the service.
MandrillTestService::handleSendResponse protected function Response handler for sent messages. Overrides MandrillService::handleSendResponse
MandrillTestService::send public function Abstracts sending of messages using PHP's built-in mail() function instead of Mandrill's sending API. Overrides MandrillService::send