class RecipientGatewayEvent in SMS Framework 8
Same name and namespace in other branches
- 2.x src/Event/RecipientGatewayEvent.php \Drupal\sms\Event\RecipientGatewayEvent
- 2.1.x src/Event/RecipientGatewayEvent.php \Drupal\sms\Event\RecipientGatewayEvent
Event fired to determine valid gateways for a recipient.
Hierarchy
- class \Drupal\sms\Event\RecipientGatewayEvent extends \Symfony\Component\EventDispatcher\Event
Expanded class hierarchy of RecipientGatewayEvent
3 files declare their use of RecipientGatewayEvent
- RecipientGatewayEventTest.php in tests/
src/ Unit/ Event/ RecipientGatewayEventTest.php - SmsMessageProcessor.php in src/
EventSubscriber/ SmsMessageProcessor.php - SmsTestEventSubscriber.php in tests/
modules/ sms_test/ src/ EventSubscriber/ SmsTestEventSubscriber.php
File
- src/
Event/ RecipientGatewayEvent.php, line 11
Namespace
Drupal\sms\EventView source
class RecipientGatewayEvent extends Event {
/**
* The recipient phone number.
*
* @var string
*/
protected $recipient;
/**
* An array of gateway doubles.
*
* @var array
* The array of gateway/priority doubles where:
* - Key 0: SmsGatewayInterface $gateway
* - Key 1: int $priority
*/
protected $gateways = [];
/**
* Constructs the object.
*
* @param string $recipient
* The recipient phone number.
*/
public function __construct($recipient) {
$this
->setRecipient($recipient);
}
/**
* Get the phone number for this event.
*
* @return string
* The phone number for this event.
*/
public function getRecipient() {
return $this->recipient;
}
/**
* Set the phone number for this event.
*
* @param string $recipient
* The phone number for this event.
*
* @return $this
* Return this event for chaining.
*/
public function setRecipient($recipient) {
$this->recipient = $recipient;
return $this;
}
/**
* Get the gateways for this event.
*
* @return array
* An array of doubles gateway/priority doubles.
*/
public function getGateways() {
return $this->gateways;
}
/**
* Return gateways ordered by priority from highest to lowest.
*
* @return \Drupal\sms\Entity\SmsGatewayInterface[]
* An array of gateways ordered by priority from highest to lowest.
*/
public function getGatewaysSorted() {
$sorted = $this->gateways;
uasort($sorted, function ($a, $b) {
list(, $priority_a) = $a;
list(, $priority_b) = $b;
if ($priority_a == $priority_b) {
return 0;
}
return $priority_a > $priority_b ? -1 : 1;
});
// Return the gateway object instead of tuples.
$gateways = [];
foreach ($sorted as $tuple) {
list($gateway, ) = $tuple;
$gateways[] = $gateway;
}
return $gateways;
}
/**
* Add a gateway for the recipient on this event.
*
* @param \Drupal\sms\Entity\SmsGatewayInterface $gateway
* The gateway for the recipient.
* @param int $priority
* The priority for this gateway.
*
* @return $this
* Return this event for chaining.
*/
public function addGateway(SmsGatewayInterface $gateway, $priority = 0) {
$this->gateways[] = [
$gateway,
$priority,
];
return $this;
}
/**
* Remove a gateway from this event.
*
* @param string $gateway_id
* A gateway plugin ID.
* @param int|null $priority
* The priority of the gateway to remove, or NULL to remove all gateways
* with the identifier.
*
* @return $this
* Return this event for chaining.
*/
public function removeGateway($gateway_id, $priority = NULL) {
foreach ($this->gateways as $k => $tuple) {
list($gateway, $gateway_priority) = $tuple;
if ($gateway_id == $gateway
->id()) {
if (!isset($priority) || $priority == $gateway_priority) {
unset($this->gateways[$k]);
}
}
}
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RecipientGatewayEvent:: |
protected | property | An array of gateway doubles. | |
RecipientGatewayEvent:: |
protected | property | The recipient phone number. | |
RecipientGatewayEvent:: |
public | function | Add a gateway for the recipient on this event. | |
RecipientGatewayEvent:: |
public | function | Get the gateways for this event. | |
RecipientGatewayEvent:: |
public | function | Return gateways ordered by priority from highest to lowest. | |
RecipientGatewayEvent:: |
public | function | Get the phone number for this event. | |
RecipientGatewayEvent:: |
public | function | Remove a gateway from this event. | |
RecipientGatewayEvent:: |
public | function | Set the phone number for this event. | |
RecipientGatewayEvent:: |
public | function | Constructs the object. |