Add dummy SMS driver and use it as the default

This commit is contained in:
Kijin Sung 2016-11-04 20:34:50 +09:00
parent 582374295d
commit 50e3dc4574
4 changed files with 63 additions and 12 deletions

View file

@ -17,6 +17,11 @@ abstract class Base implements \Rhymix\Framework\Drivers\SMSInterface
*/ */
protected static $_spec = array(); 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. * Direct invocation of the constructor is not permitted.
*/ */
@ -53,7 +58,7 @@ abstract class Base implements \Rhymix\Framework\Drivers\SMSInterface
*/ */
public static function getRequiredConfig() public static function getRequiredConfig()
{ {
return array(); return static::$_required_config;
} }
/** /**

View file

@ -15,13 +15,13 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface
'sms_max_length' => 90, 'sms_max_length' => 90,
'sms_max_length_in_charset' => 'CP949', 'sms_max_length_in_charset' => 'CP949',
'lms_supported' => true, 'lms_supported' => true,
'lms_supported_country_codes' => array(0, 82), 'lms_supported_country_codes' => array(82),
'lms_max_length' => 2000, 'lms_max_length' => 2000,
'lms_max_length_in_charset' => 'CP949', 'lms_max_length_in_charset' => 'CP949',
'lms_subject_supported' => true, 'lms_subject_supported' => true,
'lms_subject_max_length' => 40, 'lms_subject_max_length' => 40,
'mms_supported' => true, 'mms_supported' => true,
'mms_supported_country_codes' => array(0, 82), 'mms_supported_country_codes' => array(82),
'mms_max_length' => 2000, 'mms_max_length' => 2000,
'mms_max_length_in_charset' => 'CP949', 'mms_max_length_in_charset' => 'CP949',
'mms_subject_supported' => true, '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. * Config keys used by this driver are stored here.
*
* @return array
*/ */
public static function getRequiredConfig() protected static $_required_config = array('api_key', 'api_secret', 'sender_key');
{
return array('api_key', 'api_secret', 'sender_key');
}
/** /**
* Send a message. * Send a message.

View file

@ -0,0 +1,47 @@
<?php
namespace Rhymix\Framework\Drivers\SMS;
/**
* The dummy SMS driver.
*/
class Dummy extends Base implements \Rhymix\Framework\Drivers\SMSInterface
{
/**
* API specifications.
*/
protected static $_spec = array(
'max_recipients' => 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;
}
}

View file

@ -57,6 +57,10 @@ class SMS
$default_driver_config = config('sms.' . $default_driver) ?: array(); $default_driver_config = config('sms.' . $default_driver) ?: array();
self::$default_driver = $default_driver_class::getInstance($default_driver_config); self::$default_driver = $default_driver_class::getInstance($default_driver_config);
} }
else
{
self::$default_driver = Drivers\SMS\Dummy::getInstance(array());
}
} }
return self::$default_driver; return self::$default_driver;
} }
@ -595,11 +599,11 @@ class SMS
} }
// Check the country code. // 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'; $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'; $item->type = 'SMS';
} }