class SmsMessage in SMS Framework 8
Same name in this branch
- 8 src/Message/SmsMessage.php \Drupal\sms\Message\SmsMessage
- 8 src/Entity/SmsMessage.php \Drupal\sms\Entity\SmsMessage
Same name and namespace in other branches
- 2.x src/Message/SmsMessage.php \Drupal\sms\Message\SmsMessage
- 2.1.x src/Message/SmsMessage.php \Drupal\sms\Message\SmsMessage
Basic implementation of an SMS message.
Hierarchy
- class \Drupal\sms\Message\SmsMessage implements SmsMessageInterface
Expanded class hierarchy of SmsMessage
11 files declare their use of SmsMessage
- Incoming.php in tests/
modules/ sms_test_gateway/ src/ Plugin/ SmsGateway/ Incoming.php - PhoneNumberVerification.php in src/
Provider/ PhoneNumberVerification.php - SmsBlastForm.php in modules/
sms_blast/ src/ SmsBlastForm.php - SmsFrameworkDeliveryReportUpdateTest.php in tests/
src/ Kernel/ SmsFrameworkDeliveryReportUpdateTest.php - SmsFrameworkMessageEntityTest.php in tests/
src/ Kernel/ SmsFrameworkMessageEntityTest.php
File
- src/
Message/ SmsMessage.php, line 10
Namespace
Drupal\sms\MessageView source
class SmsMessage implements SmsMessageInterface {
/**
* The unique identifier for this message.
*
* @var string
*/
protected $uuid;
/**
* The sender's name.
*
* @var string|null
*/
protected $senderName;
/**
* The senders' phone number.
*
* @var string
*/
protected $senderPhoneNumber;
/**
* The recipients of the message.
*
* @var array
*/
protected $recipients = [];
/**
* The content of the message to be sent.
*
* @var string
*/
protected $message;
/**
* The gateway for this message.
*
* @var \Drupal\sms\Entity\SmsGatewayInterface
*/
protected $gateway;
/**
* The direction of the message.
*
* See \Drupal\sms\Direction constants for potential values.
*
* @var int
* @see \Drupal\sms\Direction
*/
protected $direction;
/**
* Other options to be used for the SMS.
*
* @var string
*/
protected $options = [];
/**
* The result associated with this SMS message.
*
* @var \Drupal\sms\Message\SmsMessageResultInterface|null
*/
protected $result;
/**
* The UID of the creator of the SMS message.
*
* @var int
*/
protected $uid;
/**
* Whether this message was generated automatically.
*
* @var bool
*/
protected $automated = TRUE;
/**
* Creates a new instance of an SMS message.
*
* @param string $sender_phone_number
* (optional) The senders' phone number.
* @param array $recipients
* (optional) The list of recipient phone numbers for the message.
* @param string $message
* (optional) The actual SMS message to be sent.
* @param array $options
* (optional) Additional options.
* @param int $uid
* (optional) The user who created the SMS message.
*/
public function __construct($sender_phone_number = NULL, array $recipients = [], $message = '', array $options = [], $uid = NULL) {
$this
->setSenderNumber($sender_phone_number);
$this
->addRecipients($recipients);
$this
->setMessage($message);
$this->message = $message;
$this->options = $options;
$this
->setUid($uid);
$this->uuid = $this
->uuidGenerator()
->generate();
}
/**
* {@inheritdoc}
*/
public function getSender() {
return $this->senderName;
}
/**
* {@inheritdoc}
*/
public function setSender($sender) {
$this->senderName = $sender;
return $this;
}
/**
* {@inheritdoc}
*/
public function getSenderNumber() {
return $this->senderPhoneNumber;
}
/**
* {@inheritdoc}
*/
public function setSenderNumber($number) {
$this->senderPhoneNumber = $number;
return $this;
}
/**
* {@inheritdoc}
*/
public function getMessage() {
return $this->message;
}
/**
* {@inheritdoc}
*/
public function setMessage($message) {
$this->message = $message;
return $this;
}
/**
* {@inheritdoc}
*/
public function getRecipients() {
return $this->recipients;
}
/**
* {@inheritdoc}
*/
public function addRecipient($recipient) {
if (!in_array($recipient, $this->recipients)) {
$this->recipients[] = $recipient;
}
return $this;
}
/**
* {@inheritdoc}
*/
public function addRecipients(array $recipients) {
foreach ($recipients as $recipient) {
$this
->addRecipient($recipient);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function removeRecipient($recipient) {
$this->recipients = array_values(array_diff($this->recipients, [
$recipient,
]));
return $this;
}
/**
* {@inheritdoc}
*/
public function removeRecipients(array $recipients) {
$this->recipients = array_values(array_diff($this->recipients, $recipients));
return $this;
}
/**
* {@inheritdoc}
*/
public function getGateway() {
return $this->gateway;
}
/**
* {@inheritdoc}
*/
public function setGateway(SmsGatewayInterface $gateway) {
$this->gateway = $gateway;
return $this;
}
/**
* {@inheritdoc}
*/
public function getDirection() {
return $this->direction;
}
/**
* {@inheritdoc}
*/
public function setDirection($direction) {
$this->direction = $direction;
return $this;
}
/**
* {@inheritdoc}
*/
public function getOptions() {
return $this->options;
}
/**
* {@inheritdoc}
*/
public function getOption($name) {
if (array_key_exists($name, $this->options)) {
return $this->options[$name];
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function setOption($name, $value) {
$this->options[$name] = $value;
return $this;
}
/**
* {@inheritdoc}
*/
public function removeOption($name) {
unset($this->options[$name]);
return $this;
}
/**
* {@inheritdoc}
*/
public function getResult() {
return $this->result;
}
/**
* {@inheritdoc}
*/
public function setResult(SmsMessageResultInterface $result = NULL) {
$this->result = $result;
return $this;
}
/**
* {@inheritdoc}
*/
public function getUuid() {
return $this->uuid;
}
/**
* {@inheritdoc}
*/
public function getUid() {
return $this->uid;
}
/**
* {@inheritdoc}
*/
public function setUid($uid) {
$this->uid = $uid;
return $this;
}
/**
* {@inheritdoc}
*/
public function setAutomated($automated) {
$this->automated = $automated;
return $this;
}
/**
* {@inheritdoc}
*/
public function isAutomated() {
return $this->automated;
}
/**
* Gets the UUID generator.
*
* @return \Drupal\Component\Uuid\UuidInterface
* The UUID generator.
*/
protected function uuidGenerator() {
return \Drupal::service('uuid');
}
/**
* {@inheritdoc}
*/
public function chunkByRecipients($size) {
$recipients_all = $this
->getRecipients();
// Save processing by returning early.
if ($size < 1 || count($recipients_all) <= $size) {
return [
$this,
];
}
$base = clone $this;
$base
->removeRecipients($recipients_all);
$messages = [];
foreach (array_chunk($recipients_all, $size) as $recipients) {
$message = clone $base;
$messages[] = $message
->addRecipients($recipients);
}
return $messages;
}
/**
* {@inheritdoc}
*/
public function getReport($recipient) {
return $this->result ? $this->result
->getReport($recipient) : NULL;
}
/**
* {@inheritdoc}
*/
public function getReports() {
return $this->result ? $this->result
->getReports() : [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SmsMessage:: |
protected | property | Whether this message was generated automatically. | |
SmsMessage:: |
protected | property | The direction of the message. | |
SmsMessage:: |
protected | property | The gateway for this message. | |
SmsMessage:: |
protected | property | The content of the message to be sent. | |
SmsMessage:: |
protected | property | Other options to be used for the SMS. | |
SmsMessage:: |
protected | property | The recipients of the message. | |
SmsMessage:: |
protected | property | The result associated with this SMS message. | |
SmsMessage:: |
protected | property | The sender's name. | |
SmsMessage:: |
protected | property | The senders' phone number. | |
SmsMessage:: |
protected | property | The UID of the creator of the SMS message. | |
SmsMessage:: |
protected | property | The unique identifier for this message. | |
SmsMessage:: |
public | function |
Adds a single recipient to the SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Adds multiple recipients to the SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Split this SMS message into new messages by chunks of recipients. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Get direction of the message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Get the gateway for this message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the message to be sent. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the option specified by the key $name. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the options for building or sending this SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the list of recipients of this SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the delivery report for a particular recipient. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the delivery reports for all recipients. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Get the result associated with this SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the name of the sender of this SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Get phone number of the sender. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the user who created the SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets the UUID of the SMS object. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Gets whether this SMS message was generated automatically. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Removes an option from this SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Removes a single recipient from the SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Removes multiple recipients from the SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Sets whether this SMS message was generated automatically. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Set direction of the message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Set the gateway for this message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Set the message to be sent. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Sets an option for this SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Set the result associated with this SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Set the name of the sender of this SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Set the phone number of the sender. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
public | function |
Set the user who created the SMS message. Overrides SmsMessageInterface:: |
|
SmsMessage:: |
protected | function | Gets the UUID generator. | 1 |
SmsMessage:: |
public | function | Creates a new instance of an SMS message. |