class Command in Twilio 8
Service class for Twilio API commands.
Hierarchy
- class \Drupal\twilio\Services\Command
Expanded class hierarchy of Command
1 file declares its use of Command
- TwilioAdminTestForm.php in src/
Form/ TwilioAdminTestForm.php
1 string reference to 'Command'
1 service uses Command
File
- src/
Services/ Command.php, line 12
Namespace
Drupal\twilio\ServicesView source
class Command {
private $sid;
private $token;
private $number;
/**
* Initialize properties.
*/
public function __construct() {
$this->sid = $this
->getSid();
$this->token = $this
->getToken();
$this->number = $this
->getNumber();
}
/**
* Get the Twilio Account SID.
*
* @return string
* The configured Twilio Account SID.
*/
public function getSid() {
if (empty($this->sid)) {
$this->sid = \Drupal::config('twilio.settings')
->get('account');
}
return $this->sid;
}
/**
* Get the Twilio Auth Token.
*
* @return string
* The configured Twilio Auth Token.
*/
public function getToken() {
if (empty($this->token)) {
$this->token = \Drupal::config('twilio.settings')
->get('token');
}
return $this->token;
}
/**
* Get the Twilio Number.
*
* @return string
* The configured Twilio Number.
*/
public function getNumber() {
if (empty($this->number)) {
$this->number = \Drupal::config('twilio.settings')
->get('number');
}
return $this->number;
}
/**
* Send an SMS message.
*
* @param string $number
* The number to send the message to.
* @param string|array $message
* Message text or an array:
* [
* from => number
* body => message string
* mediaUrl => absolute URL
* ].
*/
public function messageSend(string $number, $message) {
if (is_string($message)) {
$message = [
'from' => $this->number,
'body' => $message,
];
}
$message['from'] = !empty($message['from']) ? $message['from'] : $this->number;
if (empty($message['body'])) {
throw new TwilioException("Message requires a body.");
}
if (!empty($message['mediaUrl']) && !UrlHelper::isValid($message['mediaUrl'], TRUE)) {
throw new TwilioException("Media URL must be a valid, absolute URL.");
}
$client = new Client($this->sid, $this->token);
$client->messages
->create($number, $message);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Command:: |
private | property | ||
Command:: |
private | property | ||
Command:: |
private | property | ||
Command:: |
public | function | Get the Twilio Number. | |
Command:: |
public | function | Get the Twilio Account SID. | |
Command:: |
public | function | Get the Twilio Auth Token. | |
Command:: |
public | function | Send an SMS message. | |
Command:: |
public | function | Initialize properties. |