LogGateway.php in SMS Framework 8
File
src/Plugin/SmsGateway/LogGateway.php
View source
<?php
namespace Drupal\sms\Plugin\SmsGateway;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\sms\Message\SmsDeliveryReport;
use Drupal\sms\Message\SmsMessageReportStatus;
use Drupal\sms\Plugin\SmsGatewayPluginBase;
use Drupal\sms\Message\SmsMessageInterface;
use Drupal\sms\Message\SmsMessageResult;
class LogGateway extends SmsGatewayPluginBase implements ContainerFactoryPluginInterface {
protected $logger;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, LoggerChannelFactoryInterface $logger_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$definition = $this
->getPluginDefinition();
$this->logger = $logger_factory
->get($definition['provider'] . '.' . $definition['id']);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('logger.factory'));
}
public function send(SmsMessageInterface $sms) {
$this->logger
->notice('SMS message sent to %number with the text: @message', [
'%number' => implode(', ', $sms
->getRecipients()),
'@message' => $sms
->getMessage(),
]);
$result = new SmsMessageResult();
foreach ($sms
->getRecipients() as $number) {
$report = (new SmsDeliveryReport())
->setRecipient($number)
->setStatus(SmsMessageReportStatus::DELIVERED)
->setStatusMessage('DELIVERED')
->setTimeDelivered(REQUEST_TIME);
$result
->addReport($report);
}
return $result;
}
}
Classes
Name |
Description |
LogGateway |
Defines a logger gateway for testing and debugging. |