You are here

class SendMailBase in Mailgun 8

Provides base functionality for the SendMail Queue Workers.

Hierarchy

Expanded class hierarchy of SendMailBase

File

src/Plugin/QueueWorker/SendMailBase.php, line 15

Namespace

Drupal\mailgun\Plugin\QueueWorker
View source
class SendMailBase extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * Mailgun config.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $mailgunConfig;

  /**
   * Mailgun Logger instance.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * Mailgun mail handler.
   *
   * @var \Drupal\mailgun\MailgunHandlerInterface
   */
  protected $mailgunHandler;

  /**
   * SendMailBase constructor.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ImmutableConfig $settings, LoggerInterface $logger, MailgunHandlerInterface $mailgun_handler) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->mailgunConfig = $settings;
    $this->logger = $logger;
    $this->mailgunHandler = $mailgun_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('config.factory')
      ->get(MailgunHandlerInterface::CONFIG_NAME), $container
      ->get('logger.factory')
      ->get('mailgun'), $container
      ->get('mailgun.mail_handler'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $result = $this->mailgunHandler
      ->sendMail($data->message);
    if ($this->mailgunConfig
      ->get('debug_mode')) {
      $this->logger
        ->notice('Successfully sent message on CRON from %from to %to.', [
        '%from' => $data->message['from'],
        '%to' => $data->message['to'],
      ]);
    }
    if (!$result) {
      throw new \Exception('Mailgun: email did not pass through API.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SendMailBase::$logger protected property Mailgun Logger instance.
SendMailBase::$mailgunConfig protected property Mailgun config.
SendMailBase::$mailgunHandler protected property Mailgun mail handler.
SendMailBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
SendMailBase::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
SendMailBase::__construct public function SendMailBase constructor. Overrides PluginBase::__construct