class PhoneNumberProvider in SMS Framework 8
Same name and namespace in other branches
- 2.x src/Provider/PhoneNumberProvider.php \Drupal\sms\Provider\PhoneNumberProvider
- 2.1.x src/Provider/PhoneNumberProvider.php \Drupal\sms\Provider\PhoneNumberProvider
Phone number provider.
Hierarchy
- class \Drupal\sms\Provider\PhoneNumberProvider implements PhoneNumberProviderInterface
Expanded class hierarchy of PhoneNumberProvider
1 string reference to 'PhoneNumberProvider'
1 service uses PhoneNumberProvider
File
- src/
Provider/ PhoneNumberProvider.php, line 17
Namespace
Drupal\sms\ProviderView source
class PhoneNumberProvider implements PhoneNumberProviderInterface {
/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* The SMS provider.
*
* @var \Drupal\sms\Provider\SmsProviderInterface
*/
protected $smsProvider;
/**
* Constructs a new PhoneNumberProvider object.
*
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
* @param \Drupal\sms\Provider\SmsProviderInterface $sms_provider
* The SMS provider.
*/
public function __construct(EventDispatcherInterface $event_dispatcher, SmsProviderInterface $sms_provider) {
$this->eventDispatcher = $event_dispatcher;
$this->smsProvider = $sms_provider;
}
/**
* {@inheritdoc}
*/
public function getPhoneNumbers(EntityInterface $entity, $verified = TRUE) {
$event = new SmsEntityPhoneNumber($entity, $verified);
/** @var \Drupal\sms\Event\SmsEntityPhoneNumber $event */
$event = $this->eventDispatcher
->dispatch(SmsEvents::ENTITY_PHONE_NUMBERS, $event);
return $event
->getPhoneNumbers();
}
/**
* {@inheritdoc}
*/
public function sendMessage(EntityInterface $entity, SmsMessageInterface $sms_message) {
if (!($phone_numbers = $this
->getPhoneNumbers($entity))) {
throw new NoPhoneNumberException('Attempted to send an SMS to entity without a phone number.');
}
$sms_message = SmsMessageEntity::convertFromSmsMessage($sms_message)
->addRecipient(reset($phone_numbers))
->setRecipientEntity($entity)
->setDirection(Direction::OUTGOING);
$this->smsProvider
->queue($sms_message);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhoneNumberProvider:: |
protected | property | The event dispatcher. | |
PhoneNumberProvider:: |
protected | property | The SMS provider. | |
PhoneNumberProvider:: |
public | function |
Gets phone numbers for an entity. Overrides PhoneNumberProviderInterface:: |
|
PhoneNumberProvider:: |
public | function |
Sends an SMS to an entity. Overrides PhoneNumberProviderInterface:: |
|
PhoneNumberProvider:: |
public | function | Constructs a new PhoneNumberProvider object. |