-
Notifications
You must be signed in to change notification settings - Fork 0
Process eventsubscriber #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
54d0772
implemented a way to split up a message based on gateway. only done f…
dpi b80538a
event subscriber experiments
dpi 80a4e3c
Merge branch '8.x-1.x' into process-eventsubscriber
dpi df777ea
Bug fixes
dpi c780c47
Removed debug methods from processor. (almaudohTest, testAddGateway)
dpi 7356917
inject services into SmsMessageProcessor
dpi 2b13800
Add docs for events.
dpi 3e42c29
fixed clone from incorrect message.
dpi 94ca239
inject event dispatcher
dpi 6a55cf6
doc nits
dpi 901b6b9
Merge branch '8.x-1.x' into process-eventsubscriber
dpi 668963b
Addressed dispatch shortcut nits
dpi 5337f70
Ensure gateways property is not modified by uasort
dpi 76bc9ba
Added documentation for events.
dpi b85974e
oops
dpi 7d2df7b
Merge branch '8.x-1.x' into process-eventsubscriber
dpi 1c18a6d
Merge branch '8.x-1.x' into process-eventsubscriber
dpi eab24a6
Merge branch '8.x-1.x' into process-eventsubscriber
dpi 0a2a822
temporarily remove deprecation notices until a consensus is reached.
dpi 5881c27
fixed message chunking reducing from one to zero because no recipient…
dpi 99ee36d
Add a preprocess to detect if messages have no recipients.
dpi 31560d0
Fixed some failing tests popping up as a result of new no-recipient e…
dpi 0e1e3a6
Merge branch '8.x-1.x' into process-eventsubscriber
dpi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| <?php | ||
|
|
||
| namespace Drupal\sms\Event; | ||
|
|
||
| use Symfony\Component\EventDispatcher\Event; | ||
| use Drupal\sms\Entity\SmsGatewayInterface; | ||
|
|
||
| /** | ||
| * Event fired to determine valid gateways for a recipient. | ||
| */ | ||
| 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: integer $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[] | ||
| */ | ||
| public function getGatewaysSorted() { | ||
| $gateways = $this->gateways; | ||
| uasort($gateways, 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; | ||
| }); | ||
|
|
||
| $gateways = []; | ||
| foreach ($gateways 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 $gateway_id | ||
| * A gateway plugin ID. | ||
| * | ||
| * @param integer|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; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php | ||
|
|
||
| namespace Drupal\sms\Event; | ||
|
|
||
| use Symfony\Component\EventDispatcher\Event; | ||
|
|
||
| /** | ||
| * Event fired when a new SMS message is being processed before or after send or | ||
| * queue. | ||
| */ | ||
| class SmsMessageEvent extends Event { | ||
|
|
||
| /** | ||
| * The SMS messages. | ||
| * | ||
| * @var \Drupal\sms\Message\SmsMessageInterface[] | ||
| */ | ||
| protected $messages; | ||
|
|
||
| /** | ||
| * Constructs the object. | ||
| * | ||
| * @param \Drupal\sms\Message\SmsMessageInterface[] $messages | ||
| * The SMS message. | ||
| */ | ||
| public function __construct(array $messages) { | ||
| $this->setMessages($messages); | ||
| } | ||
|
|
||
| /** | ||
| * Get all messages on this event. | ||
| * | ||
| * @return \Drupal\sms\Message\SmsMessageInterface[] | ||
| * The messages on this event. | ||
| */ | ||
| public function getMessages() { | ||
| return $this->messages; | ||
| } | ||
|
|
||
| /** | ||
| * Set the messages on this event. | ||
| * | ||
| * @param $messages | ||
| * The messages to set on this event. | ||
| * | ||
| * @return $this | ||
| * Returns this event for chaining. | ||
| */ | ||
| public function setMessages($messages) { | ||
| $this->messages = $messages; | ||
| return $this; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a second event?