You are here

class EmailQueue in Search API Saved Searches 8

Provides functionality for sending e-mails at the end of the page request.

Hierarchy

Expanded class hierarchy of EmailQueue

1 string reference to 'EmailQueue'
search_api_saved_searches.services.yml in ./search_api_saved_searches.services.yml
search_api_saved_searches.services.yml
1 service uses EmailQueue
search_api_saved_searches.email_queue in ./search_api_saved_searches.services.yml
Drupal\search_api_saved_searches\Service\EmailQueue

File

src/Service/EmailQueue.php, line 11

Namespace

Drupal\search_api_saved_searches\Service
View source
class EmailQueue implements DestructableInterface {

  /**
   * The mail manager service.
   *
   * @var \Drupal\Core\Mail\MailManagerInterface
   */
  protected $mail;

  /**
   * The queued mails, as argument arrays.
   *
   * @var array[]
   */
  protected $mails = [];

  /**
   * Constructs a new class instance.
   *
   * @param \Drupal\Core\Mail\MailManagerInterface $mail
   *   The mail manager service.
   */
  public function __construct(MailManagerInterface $mail) {
    $this->mail = $mail;
  }

  /**
   * Queues an e-mail to be sent.
   *
   * @param array $args
   *   The arguments that should be passed when sending the mail.
   *
   * @see \Drupal\Core\Mail\MailManagerInterface::mail()
   */
  public function queueMail(array $args) {
    $this->mails[] = $args;
  }

  /**
   * {@inheritdoc}
   */
  public function destruct() {
    foreach ($this->mails as $i => $args) {
      call_user_func_array([
        $this->mail,
        'mail',
      ], $args);
      unset($this->mails[$i]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EmailQueue::$mail protected property The mail manager service.
EmailQueue::$mails protected property The queued mails, as argument arrays.
EmailQueue::destruct public function Performs destruct operations. Overrides DestructableInterface::destruct
EmailQueue::queueMail public function Queues an e-mail to be sent.
EmailQueue::__construct public function Constructs a new class instance.