class SmsProcessor in SMS Framework 8
Transmits SMS messages.
Plugin annotation
@QueueWorker(
id = "sms.messages",
title = @Translation("SMS message processor"),
cron = {"time" = 60}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\sms\Plugin\QueueWorker\SmsProcessor implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of SmsProcessor
File
- src/
Plugin/ QueueWorker/ SmsProcessor.php, line 21
Namespace
Drupal\sms\Plugin\QueueWorkerView source
class SmsProcessor extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* The SMS provider.
*
* @var \Drupal\sms\Provider\SmsProviderInterface
*/
protected $smsProvider;
/**
* SMS message entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $smsMessageStorage;
/**
* Constructs a new SmsProcessor object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\sms\Provider\SmsProviderInterface $sms_provider
* The SMS provider.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, SmsProviderInterface $sms_provider) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->smsMessageStorage = $entity_type_manager
->getStorage('sms');
$this->smsProvider = $sms_provider;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('sms.provider'));
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
if (isset($data['id'])) {
$id = $data['id'];
/** @var \Drupal\sms\Entity\SmsMessageInterface $sms_message */
if ($sms_message = $this->smsMessageStorage
->load($id)) {
switch ($sms_message
->getDirection()) {
case Direction::INCOMING:
$this->smsProvider
->incoming($sms_message);
break;
case Direction::OUTGOING:
$this->smsProvider
->send($sms_message);
break;
}
$duration = NULL;
if ($gateway = $sms_message
->getGateway()) {
$duration = $gateway
->getRetentionDuration($sms_message
->getDirection());
}
// Clean up SMS message now if retention is set to delete immediately.
if ($duration === 0) {
$sms_message
->delete();
}
else {
$sms_message
->setProcessedTime(REQUEST_TIME)
->setQueued(FALSE)
->save();
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SmsProcessor:: |
protected | property | SMS message entity storage. | |
SmsProcessor:: |
protected | property | The SMS provider. | |
SmsProcessor:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
SmsProcessor:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
SmsProcessor:: |
public | function |
Constructs a new SmsProcessor object. Overrides PluginBase:: |