You are here

class SwiftMailerDrupalStateLogger in Swift Mailer 8

Same name and namespace in other branches
  1. 8.2 tests/modules/swiftmailer_test/src/SwiftMailerDrupalStateLogger.php \Drupal\swiftmailer_test\SwiftMailerDrupalStateLogger

Hierarchy

Expanded class hierarchy of SwiftMailerDrupalStateLogger

2 files declare their use of SwiftMailerDrupalStateLogger
SwiftMailerAlterTest.php in tests/src/Functional/SwiftMailerAlterTest.php
swiftmailer_test.module in tests/modules/swiftmailer_test/swiftmailer_test.module

File

tests/modules/swiftmailer_test/src/SwiftMailerDrupalStateLogger.php, line 8

Namespace

Drupal\swiftmailer_test
View source
class SwiftMailerDrupalStateLogger implements Swift_Events_SendListener {
  public function beforeSendPerformed(Swift_Events_SendEvent $evt) {
    $this
      ->add([
      'method' => 'beforeSendPerformed',
      'body' => $evt
        ->getMessage()
        ->getBody(),
      'subject' => $evt
        ->getMessage()
        ->getSubject(),
    ]);
  }
  public function sendPerformed(Swift_Events_SendEvent $evt) {
    $this
      ->add([
      'method' => 'sendPerformed',
      'body' => $evt
        ->getMessage()
        ->getBody(),
      'subject' => $evt
        ->getMessage()
        ->getSubject(),
    ]);
  }
  public function add($entry) {
    $captured_emails = \Drupal::state()
      ->get('swiftmailer.mail_collector') ?: [];
    $captured_emails[] = $entry;
    \Drupal::state()
      ->set('swiftmailer.mail_collector', $captured_emails);
  }
  public function clear() {
    \Drupal::state()
      ->delete('swiftmailer.mail_collector');
  }
  public function dump() {
    return \Drupal::state()
      ->get('swiftmailer.mail_collector', []);
  }

}

Members