From 10309e58115b514081303680270d7414d441375b Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 10 May 2016 15:58:26 +0900 Subject: [PATCH] Standardize config field names, and make drivers declare which fields they require --- common/framework/drivers/mail/base.php | 20 +++++++++++++++++ common/framework/drivers/mail/ses.php | 24 +++++++++++++++++++-- common/framework/drivers/mail/smtp.php | 16 +++++++++++--- common/framework/drivers/mail/sparkpost.php | 10 +++++++++ common/framework/drivers/mail/woorimail.php | 20 +++++++++++++++++ common/framework/drivers/mailinterface.php | 14 ++++++++++++ 6 files changed, 99 insertions(+), 5 deletions(-) diff --git a/common/framework/drivers/mail/base.php b/common/framework/drivers/mail/base.php index 9a671d144..69b0f0215 100644 --- a/common/framework/drivers/mail/base.php +++ b/common/framework/drivers/mail/base.php @@ -46,6 +46,26 @@ abstract class Base implements \Rhymix\Framework\Drivers\MailInterface return class_basename(get_called_class()); } + /** + * Get the list of configuration fields required by this mail driver. + * + * @return array + */ + public static function getRequiredConfig() + { + return array(); + } + + /** + * Get the list of API types supported by this mail driver. + * + * @return array + */ + public static function getAPITypes() + { + return array(); + } + /** * Check if the current mail driver is supported on this server. * diff --git a/common/framework/drivers/mail/ses.php b/common/framework/drivers/mail/ses.php index 45d578409..85b3755aa 100644 --- a/common/framework/drivers/mail/ses.php +++ b/common/framework/drivers/mail/ses.php @@ -17,12 +17,32 @@ class SES extends Base implements \Rhymix\Framework\Drivers\MailInterface */ protected function __construct(array $config) { - $transport = \Swift_AWSTransport::newInstance($config['user'], $config['pass']); + $transport = \Swift_AWSTransport::newInstance($config['api_user'], $config['api_pass']); $transport->setDebug(array($this, 'debugCallback')); - $transport->setEndpoint('https://email.' . strtolower($config['type']) . '.amazonaws.com/'); + $transport->setEndpoint('https://email.' . strtolower($config['api_type']) . '.amazonaws.com/'); $this->mailer = \Swift_Mailer::newInstance($transport); } + /** + * Get the list of configuration fields required by this mail driver. + * + * @return array + */ + public static function getRequiredConfig() + { + return array('api_user', 'api_pass', 'api_type'); + } + + /** + * Get the list of API types supported by this mail driver. + * + * @return array + */ + public static function getAPITypes() + { + return array('us-east-1', 'us-west-2', 'eu-west-1'); + } + /** * Check if the current mail driver is supported on this server. * diff --git a/common/framework/drivers/mail/smtp.php b/common/framework/drivers/mail/smtp.php index 5b2259e0c..5e17a6c78 100644 --- a/common/framework/drivers/mail/smtp.php +++ b/common/framework/drivers/mail/smtp.php @@ -12,9 +12,9 @@ class SMTP extends Base implements \Rhymix\Framework\Drivers\MailInterface */ protected function __construct(array $config) { - $transport = \Swift_SmtpTransport::newInstance($config['host'], $config['port'], $config['secure']); - $transport->setUsername($config['user']); - $transport->setPassword($config['pass']); + $transport = \Swift_SmtpTransport::newInstance($config['smtp_host'], $config['smtp_port'], $config['smtp_security']); + $transport->setUsername($config['smtp_user']); + $transport->setPassword($config['smtp_pass']); $local_domain = $transport->getLocalDomain(); if (preg_match('/^\*\.(.+)$/', $local_domain, $matches)) { @@ -23,6 +23,16 @@ class SMTP extends Base implements \Rhymix\Framework\Drivers\MailInterface $this->mailer = \Swift_Mailer::newInstance($transport); } + /** + * Get the list of configuration fields required by this mail driver. + * + * @return array + */ + public static function getRequiredConfig() + { + return array('smtp_host', 'smtp_port', 'smtp_security', 'smtp_user', 'smtp_pass'); + } + /** * Check if the current mail driver is supported on this server. * diff --git a/common/framework/drivers/mail/sparkpost.php b/common/framework/drivers/mail/sparkpost.php index 544ae40b1..7e4ed992d 100644 --- a/common/framework/drivers/mail/sparkpost.php +++ b/common/framework/drivers/mail/sparkpost.php @@ -12,6 +12,16 @@ class SparkPost extends Base implements \Rhymix\Framework\Drivers\MailInterface */ protected static $_url = 'https://api.sparkpost.com/api/v1/transmissions'; + /** + * Get the list of configuration fields required by this mail driver. + * + * @return array + */ + public static function getRequiredConfig() + { + return array('api_token'); + } + /** * Check if the current mail driver is supported on this server. * diff --git a/common/framework/drivers/mail/woorimail.php b/common/framework/drivers/mail/woorimail.php index e6caf4851..7aee06ed7 100644 --- a/common/framework/drivers/mail/woorimail.php +++ b/common/framework/drivers/mail/woorimail.php @@ -31,6 +31,26 @@ class Woorimail extends Base implements \Rhymix\Framework\Drivers\MailInterface 'me_013' => '전용채널에 도메인이 등록되어 있지 않습니다.', ); + /** + * Get the list of configuration fields required by this mail driver. + * + * @return array + */ + public static function getRequiredConfig() + { + return array('api_domain', 'api_token', 'api_type'); + } + + /** + * Get the list of API types supported by this mail driver. + * + * @return array + */ + public static function getAPITypes() + { + return array('free', 'paid'); + } + /** * Check if the current mail driver is supported on this server. * diff --git a/common/framework/drivers/mailinterface.php b/common/framework/drivers/mailinterface.php index 2f8bb8a10..03385ebc4 100644 --- a/common/framework/drivers/mailinterface.php +++ b/common/framework/drivers/mailinterface.php @@ -22,6 +22,20 @@ interface MailInterface */ public static function getName(); + /** + * Get the list of configuration fields required by this mail driver. + * + * @return array + */ + public static function getRequiredConfig(); + + /** + * Get the list of API types supported by this mail driver. + * + * @return array + */ + public static function getAPITypes(); + /** * Check if the current mail driver is supported on this server. *