From 50e3dc4574a2aaf4b70653d76428d2ca24c14496 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 4 Nov 2016 20:34:50 +0900 Subject: [PATCH] Add dummy SMS driver and use it as the default --- common/framework/drivers/sms/base.php | 7 +++- common/framework/drivers/sms/coolsms.php | 13 ++----- common/framework/drivers/sms/dummy.php | 47 ++++++++++++++++++++++++ common/framework/sms.php | 8 +++- 4 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 common/framework/drivers/sms/dummy.php diff --git a/common/framework/drivers/sms/base.php b/common/framework/drivers/sms/base.php index 26e38ea62..15c1b5610 100644 --- a/common/framework/drivers/sms/base.php +++ b/common/framework/drivers/sms/base.php @@ -17,6 +17,11 @@ abstract class Base implements \Rhymix\Framework\Drivers\SMSInterface */ protected static $_spec = array(); + /** + * Config keys used by this driver are stored here. + */ + protected static $_required_config = array(); + /** * Direct invocation of the constructor is not permitted. */ @@ -53,7 +58,7 @@ abstract class Base implements \Rhymix\Framework\Drivers\SMSInterface */ public static function getRequiredConfig() { - return array(); + return static::$_required_config; } /** diff --git a/common/framework/drivers/sms/coolsms.php b/common/framework/drivers/sms/coolsms.php index d08778c21..b7068afc3 100644 --- a/common/framework/drivers/sms/coolsms.php +++ b/common/framework/drivers/sms/coolsms.php @@ -15,13 +15,13 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface 'sms_max_length' => 90, 'sms_max_length_in_charset' => 'CP949', 'lms_supported' => true, - 'lms_supported_country_codes' => array(0, 82), + 'lms_supported_country_codes' => array(82), 'lms_max_length' => 2000, 'lms_max_length_in_charset' => 'CP949', 'lms_subject_supported' => true, 'lms_subject_max_length' => 40, 'mms_supported' => true, - 'mms_supported_country_codes' => array(0, 82), + 'mms_supported_country_codes' => array(82), 'mms_max_length' => 2000, 'mms_max_length_in_charset' => 'CP949', 'mms_subject_supported' => true, @@ -33,14 +33,9 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface ); /** - * Get the list of configuration fields required by this mail driver. - * - * @return array + * Config keys used by this driver are stored here. */ - public static function getRequiredConfig() - { - return array('api_key', 'api_secret', 'sender_key'); - } + protected static $_required_config = array('api_key', 'api_secret', 'sender_key'); /** * Send a message. diff --git a/common/framework/drivers/sms/dummy.php b/common/framework/drivers/sms/dummy.php new file mode 100644 index 000000000..8c85ca794 --- /dev/null +++ b/common/framework/drivers/sms/dummy.php @@ -0,0 +1,47 @@ + 100, + 'sms_max_length' => 90, + 'sms_max_length_in_charset' => 'CP949', + 'lms_supported' => true, + 'lms_supported_country_codes' => array(82), + 'lms_max_length' => 2000, + 'lms_max_length_in_charset' => 'CP949', + 'lms_subject_supported' => true, + 'lms_subject_max_length' => 40, + 'mms_supported' => true, + 'mms_supported_country_codes' => array(82), + 'mms_max_length' => 2000, + 'mms_max_length_in_charset' => 'CP949', + 'mms_subject_supported' => false, + 'mms_subject_max_length' => 40, + 'image_allowed_types' => array(), + 'image_max_dimensions' => array(1024, 1024), + 'image_max_filesize' => 300000, + 'delay_supported' => true, + ); + + /** + * Send a message. + * + * This method returns true on success and false on failure. + * + * @param array $messages + * @return bool + */ + public function send(array $messages) + { + return true; + } +} diff --git a/common/framework/sms.php b/common/framework/sms.php index 797192cfe..730a75d2e 100644 --- a/common/framework/sms.php +++ b/common/framework/sms.php @@ -57,6 +57,10 @@ class SMS $default_driver_config = config('sms.' . $default_driver) ?: array(); self::$default_driver = $default_driver_class::getInstance($default_driver_config); } + else + { + self::$default_driver = Drivers\SMS\Dummy::getInstance(array()); + } } return self::$default_driver; } @@ -595,11 +599,11 @@ class SMS } // Check the country code. - if ($item->type === 'MMS' && is_array($spec['mms_supported_country_codes']) && !in_array($country_code, $spec['mms_supported_country_codes'])) + if ($item->type === 'MMS' && $country_code && is_array($spec['mms_supported_country_codes']) && !in_array($country_code, $spec['mms_supported_country_codes'])) { $item->type = 'LMS'; } - if ($item->type === 'LMS' && is_array($spec['lms_supported_country_codes']) && !in_array($country_code, $spec['lms_supported_country_codes'])) + if ($item->type === 'LMS' && $country_code && is_array($spec['lms_supported_country_codes']) && !in_array($country_code, $spec['lms_supported_country_codes'])) { $item->type = 'SMS'; }