Differential D8930 Diff 21194 src/infrastructure/sms/adapter/PhabricatorSMSImplementationAdapter.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/sms/adapter/PhabricatorSMSImplementationAdapter.php
- This file was added.
<?php | |||||
abstract class PhabricatorSMSImplementationAdapter { | |||||
private $fromNumber; | |||||
private $toNumber; | |||||
private $body; | |||||
public function setFrom($number) { | |||||
$this->fromNumber = $number; | |||||
return $this; | |||||
} | |||||
public function getFrom() { | |||||
return $this->fromNumber; | |||||
} | |||||
public function setTo($number) { | |||||
$this->toNumber = $number; | |||||
return $this; | |||||
} | |||||
public function getTo() { | |||||
return $this->toNumber; | |||||
} | |||||
public function setBody($body) { | |||||
$this->body = $body; | |||||
return $this; | |||||
} | |||||
public function getBody() { | |||||
return $this->body; | |||||
} | |||||
/** | |||||
* Send the message. Generally, this means connecting to some service and | |||||
* handing data to it. | |||||
* | |||||
* If the adapter determines that the SMS will never be deliverable, it | |||||
* should throw an exception. | |||||
* | |||||
* For temporary failures, throw some other exception or return `false`. | |||||
* | |||||
* @return bool True on success. | |||||
epriestley: (We should probably move away from this pattern -- in MetaMTA too -- and just use "throw on… | |||||
*/ | |||||
abstract public function send(); | |||||
/** | |||||
* Convenience function to handling sending an SMS. | |||||
*/ | |||||
public static function sendSMS(array $to_numbers, $body) { | |||||
$adapter = PhabricatorEnv::getEnvConfig('sms.default-adapter'); | |||||
$from_number = PhabricatorEnv::getEnvConfig('sms.default-sender'); | |||||
PhabricatorWorker::scheduleTask( | |||||
'PhabricatorSMSDemultiplexer', | |||||
array( | |||||
'fromNumber' => $from_number, | |||||
'toNumbers' => $to_numbers, | |||||
'body' => $body, | |||||
'adapter' => $adapter)); | |||||
} | |||||
} | |||||
btrahanAuthorUnsubmitted Not Done Inline Actionsthis could easily just for a foreach ($to_numbers) and kill the DemultiplexWorker btrahan: this could easily just for a foreach ($to_numbers) and kill the DemultiplexWorker | |||||
epriestleyUnsubmitted Not Done Inline ActionsYeah maybe a good call for v1. This is just an INSERT and I think it will be rare that we need to send a whole lot of SMSes at once. epriestley: Yeah maybe a good call for v1. This is just an INSERT and I think it will be rare that we need… |
(We should probably move away from this pattern -- in MetaMTA too -- and just use "throw on failure, don't throw on success". The MetaMTA code would be simpler for it, and everything else everywhere does that.)