You are here

public function SmsMessageProcessor::ensureIncomingSupport in SMS Framework 8

Same name and namespace in other branches
  1. 2.x src/EventSubscriber/SmsMessageProcessor.php \Drupal\sms\EventSubscriber\SmsMessageProcessor::ensureIncomingSupport()
  2. 2.1.x src/EventSubscriber/SmsMessageProcessor.php \Drupal\sms\EventSubscriber\SmsMessageProcessor::ensureIncomingSupport()

Ensures gateway supports incoming messages.

Parameters

\Drupal\sms\Event\SmsMessageEvent $event: An SMS message process event.

File

src/EventSubscriber/SmsMessageProcessor.php, line 64

Class

SmsMessageProcessor
Handles messages before they are processed by queue(), send(), or incoming().

Namespace

Drupal\sms\EventSubscriber

Code

public function ensureIncomingSupport(SmsMessageEvent $event) {
  $sms_messages = $event
    ->getMessages();
  foreach ($sms_messages as $sms_message) {
    if ($sms_message
      ->getDirection() == Direction::INCOMING) {
      $gateway = $sms_message
        ->getGateway();
      if (!$gateway instanceof SmsGatewayInterface) {
        throw new SmsException('Gateway not set on incoming message');
      }
      if (!$gateway
        ->supportsIncoming()) {
        throw new SmsException(sprintf('Gateway `%s` does not support incoming messages.', $gateway
          ->id()));
      }
    }
  }
}