You are here

protected function SmsMessageProcessor::getGatewayForPhoneNumber in SMS Framework 2.x

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

Get a gateway for a phone number.

Parameters

string $recipient: A recipient phone number.

Return value

\Drupal\sms\Entity\SmsGatewayInterface|null A gateway for the phone number, or NULL if there is no gateway.

1 call to SmsMessageProcessor::getGatewayForPhoneNumber()
SmsMessageProcessor::ensureGateways in src/EventSubscriber/SmsMessageProcessor.php
Ensure all recipients are routed to a gateway.

File

src/EventSubscriber/SmsMessageProcessor.php, line 223

Class

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

Namespace

Drupal\sms\EventSubscriber

Code

protected function getGatewayForPhoneNumber($recipient) {
  $event = new RecipientGatewayEvent($recipient);

  /** @var \Drupal\sms\Event\RecipientGatewayEvent $event */
  $event = $this->eventDispatcher
    ->dispatch(SmsEvents::MESSAGE_GATEWAY, $event);
  $gateways = $event
    ->getGatewaysSorted();

  // Use the gateway with the greatest weight.
  $gateway = array_shift($gateways);
  if ($gateway instanceof SmsGatewayInterface) {
    return $gateway;
  }

  // If no gateways found for a phone number, use site fallback default if
  // available.
  $gateway_id = $this->configFactory
    ->get('sms.settings')
    ->get('fallback_gateway');
  return isset($gateway_id) ? SmsGateway::load($gateway_id) : NULL;
}