From ddc0da173aabe85c4eb982efb59bb79c82e483bd Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sat, 12 Nov 2016 15:17:32 +0900 Subject: [PATCH] Minor adjustments to make configuration easier --- common/framework/drivers/sms/base.php | 13 ++++++++++++- common/framework/drivers/sms/coolsms.php | 15 ++++++++++++++- common/framework/drivers/sms/dummy.php | 12 ++++++++++++ common/framework/drivers/smsinterface.php | 7 +++++++ common/framework/sms.php | 2 ++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/common/framework/drivers/sms/base.php b/common/framework/drivers/sms/base.php index 0349d5e5a..5d7ff7921 100644 --- a/common/framework/drivers/sms/base.php +++ b/common/framework/drivers/sms/base.php @@ -21,6 +21,7 @@ abstract class Base implements \Rhymix\Framework\Drivers\SMSInterface * Config keys used by this driver are stored here. */ protected static $_required_config = array(); + protected static $_optional_config = array(); /** * Direct invocation of the constructor is not permitted. @@ -61,6 +62,16 @@ abstract class Base implements \Rhymix\Framework\Drivers\SMSInterface return static::$_required_config; } + /** + * Get the list of configuration fields optionally used by this SMS driver. + * + * @return array + */ + public static function getOptionalConfig() + { + return static::$_optional_config; + } + /** * Get the list of API types supported by this SMS driver. * @@ -90,7 +101,7 @@ abstract class Base implements \Rhymix\Framework\Drivers\SMSInterface */ public static function isSupported() { - return true; + return false; } /** diff --git a/common/framework/drivers/sms/coolsms.php b/common/framework/drivers/sms/coolsms.php index 2a9af7df1..f18c8667e 100644 --- a/common/framework/drivers/sms/coolsms.php +++ b/common/framework/drivers/sms/coolsms.php @@ -35,7 +35,20 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface /** * Config keys used by this driver are stored here. */ - protected static $_required_config = array('api_key', 'api_secret', 'sender_key'); + protected static $_required_config = array('api_key', 'api_secret'); + protected static $_optional_config = array('sender_key'); + + /** + * Check if the current SMS driver is supported on this server. + * + * This method returns true on success and false on failure. + * + * @return bool + */ + public static function isSupported() + { + return true; + } /** * Send a message. diff --git a/common/framework/drivers/sms/dummy.php b/common/framework/drivers/sms/dummy.php index 43f97b299..a39804a49 100644 --- a/common/framework/drivers/sms/dummy.php +++ b/common/framework/drivers/sms/dummy.php @@ -37,6 +37,18 @@ class Dummy extends Base implements \Rhymix\Framework\Drivers\SMSInterface */ protected $_sent_messages = array(); + /** + * Check if the current SMS driver is supported on this server. + * + * This method returns true on success and false on failure. + * + * @return bool + */ + public static function isSupported() + { + return true; + } + /** * Send a message. * diff --git a/common/framework/drivers/smsinterface.php b/common/framework/drivers/smsinterface.php index 6a88fed10..122271933 100644 --- a/common/framework/drivers/smsinterface.php +++ b/common/framework/drivers/smsinterface.php @@ -29,6 +29,13 @@ interface SMSInterface */ public static function getRequiredConfig(); + /** + * Get the list of configuration fields optionally used by this SMS driver. + * + * @return array + */ + public static function getOptionalConfig(); + /** * Get the list of API types supported by this SMS driver. * diff --git a/common/framework/sms.php b/common/framework/sms.php index fbbd03c10..9a6d6133d 100644 --- a/common/framework/sms.php +++ b/common/framework/sms.php @@ -90,6 +90,7 @@ class SMS $result[$driver_name] = array( 'name' => $class_name::getName(), 'required' => $class_name::getRequiredConfig(), + 'optional' => $class_name::getOptionalConfig(), 'api_types' => $class_name::getAPITypes(), 'api_spec' => $class_name::getAPISpec(), ); @@ -102,6 +103,7 @@ class SMS $result[strtolower(class_basename($driver))] = array( 'name' => $driver->getName(), 'required' => $driver->getRequiredConfig(), + 'optional' => $driver->getOptionalConfig(), 'api_types' => $driver->getAPITypes(), 'api_spec' => $class_name::getAPISpec(), );