diff --git a/modules/sms_track/sms_track.module b/modules/sms_track/sms_track.module index f4e3bec..6afe938 100644 --- a/modules/sms_track/sms_track.module +++ b/modules/sms_track/sms_track.module @@ -63,10 +63,10 @@ function sms_track_sms_send(SmsMessageInterface $sms, array $options, GatewayInt * Additional options array including sender. * @param \Drupal\sms\Gateway\GatewayInterface $gateway * Gateway array for the active gateway. - * @param array $result - * Result array from the gateway response handler. + * @param bool|array $result + * The result from the gateway response handler. */ -function sms_track_sms_send_process($op, SmsMessageInterface $sms, array $options, GatewayInterface $gateway, array $result) { +function sms_track_sms_send_process($op, SmsMessageInterface $sms, array $options, GatewayInterface $gateway, $result) { if ($op == 'post process') { // Archiving (outgoing == 0) $dir = 0; diff --git a/src/Gateway/GatewayBase.php b/src/Gateway/GatewayBase.php index 75b8cce..428caa6 100644 --- a/src/Gateway/GatewayBase.php +++ b/src/Gateway/GatewayBase.php @@ -9,7 +9,7 @@ namespace Drupal\sms\Gateway; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\StringTranslation\StringTranslationTrait; +use Symfony\Component\HttpFoundation\Request; /** * Base class for sms gateway plugins. @@ -168,6 +168,27 @@ abstract class GatewayBase extends PluginBase implements GatewayInterface { } /** + * {@inheritdoc} + */ + public function balance() { + return 0; + } + + /** + * {@inheritdoc} + */ + public function deliveryReport(Request $request) { + return; + } + + /** + * {@inheritdoc} + */ + public function getError() { + return array(); + } + + /** * Gets the Psr logger for this gateway. */ protected function logger() { diff --git a/src/Gateway/GatewayInterface.php b/src/Gateway/GatewayInterface.php index 9d3aea8..48f0f85 100644 --- a/src/Gateway/GatewayInterface.php +++ b/src/Gateway/GatewayInterface.php @@ -18,9 +18,6 @@ use Symfony\Component\HttpFoundation\Request; */ interface GatewayInterface extends ConfigurablePluginInterface, PluginFormInterface { - // Gateway response codes - // 0=Unknown, 2xx=Positive, 4xx=Negative(likely client err), 5xx=Negative(likely gateway err) - /** * Status Unknown. * @@ -114,15 +111,6 @@ interface GatewayInterface extends ConfigurablePluginInterface, PluginFormInterf const STATUS_ERR_OTHER = 500; /** - * Use get - * Connection methods - */ - const HTTP_GET_SPLIT = 0; - const HTTP_GET = 1; - const HTTP_POST = 2; - const SMPP = 3; - - /** * Sends an sms and invokes the corresponding sms receipt method. * * @param \Drupal\sms\Message\SmsMessageInterface $sms diff --git a/src/Gateway/GatewayManager.php b/src/Gateway/GatewayManager.php index 105b633..63ea7ee 100644 --- a/src/Gateway/GatewayManager.php +++ b/src/Gateway/GatewayManager.php @@ -196,9 +196,7 @@ class GatewayManager extends DefaultPluginManager implements GatewayManagerInter foreach ($instance_configs as $id => $instance_config) { // Note that DefaultFactory::createInstance will get the right definitions. if (!isset($instance_config['plugin_id'])) { - // @todo Throw exception here??? -// throw new \InvalidArgumentException(sprintf('Gateway %s configured without a plugin id.', $id)); - continue; + throw new \InvalidArgumentException(sprintf('Gateway %s configured without a plugin id.', $id)); } $this->gateways[$id] = $this->createInstance($instance_config['plugin_id'], $instance_config); $this->names[$id] = $this->gateways[$id]->getLabel(); diff --git a/src/Gateway/HookGateway.php b/src/Gateway/HookGateway.php index a57092c..9c7c134 100644 --- a/src/Gateway/HookGateway.php +++ b/src/Gateway/HookGateway.php @@ -46,6 +46,9 @@ class HookGateway extends GatewayBase { * {@inheritdoc} */ public function balance() { + if (is_callable($this->pluginDefinition['balance'])) { + return $this->pluginDefinition['balance'](); + } return 0; } @@ -53,14 +56,9 @@ class HookGateway extends GatewayBase { * {@inheritdoc} */ public function deliveryReport(Request $request) { - return; - } - - /** - * {@inheritdoc} - */ - public function getError() { - return array(); + if (is_callable($this->pluginDefinition['delivery report'])) { + return $this->pluginDefinition['delivery report'](); + } } /** diff --git a/src/Plugin/Gateway/LogGateway.php b/src/Plugin/Gateway/LogGateway.php index 4e5c08d..59e0a2a 100644 --- a/src/Plugin/Gateway/LogGateway.php +++ b/src/Plugin/Gateway/LogGateway.php @@ -9,7 +9,6 @@ namespace Drupal\sms\Plugin\Gateway; use Drupal\sms\Gateway\GatewayBase; use Drupal\sms\Message\SmsMessageInterface; use Drupal\sms\Message\SmsMessageResult; -use Symfony\Component\HttpFoundation\Request; /** * @SmsGateway( @@ -22,35 +21,12 @@ class LogGateway extends GatewayBase { /** * {@inheritdoc} - * - * Log sms message to drupal watchdog(). */ public function send(SmsMessageInterface $sms, array $options) { + // Log sms message to drupal logger. $this->logger()->notice('SMS message sent to %number with the text: @message', ['%number' => implode(', ', $sms->getRecipients()), '@message' => $sms->getMessage()]); return new SmsMessageResult(['status' => TRUE]); } - - /** - * {@inheritdoc} - */ - public function balance() { - return 0; - } - - /** - * {@inheritdoc} - */ - public function deliveryReport(Request $request) { - return; - } - - /** - * {@inheritdoc} - */ - public function getError() { - return array(); - } - } diff --git a/src/Provider/DefaultSmsProvider.php b/src/Provider/DefaultSmsProvider.php index 7e37752..712cac0 100644 --- a/src/Provider/DefaultSmsProvider.php +++ b/src/Provider/DefaultSmsProvider.php @@ -121,10 +121,10 @@ class DefaultSmsProvider implements SmsProviderInterface { * Additional options that were passed to the SMS gateway. * @param \Drupal\sms\Gateway\GatewayInterface $gateway * The default gateway for sending this message. - * @param array $result - * The result returned from SMS sending. + * @param bool|array $result + * The result from the gateway response handler. */ - protected function postProcess(SmsMessageInterface $sms, array $options, GatewayInterface $gateway, array $result) { + protected function postProcess(SmsMessageInterface $sms, array $options, GatewayInterface $gateway, $result) { // Call the send post process hooks. $this->moduleHandler->invokeAll('sms_send_process', ['post process', $sms, $options, $gateway, $result]); }