Add ability to register custom mail drivers

This commit is contained in:
Kijin Sung 2016-04-26 09:31:32 +09:00
parent fedc7efc59
commit 7303d3b2aa
2 changed files with 32 additions and 15 deletions

View file

@ -33,13 +33,13 @@ class Mail extends Rhymix\Framework\Mail
*/ */
public static function useSMTP($auth = null, $host = null, $user = null, $pass = null, $secure = null, $port = 25) public static function useSMTP($auth = null, $host = null, $user = null, $pass = null, $secure = null, $port = 25)
{ {
self::$default_transport = Rhymix\Framework\Drivers\Mail\SMTP::getInstance(array( self::setDefaultDriver(Rhymix\Framework\Drivers\Mail\SMTP::getInstance(array(
'host' => $host, 'host' => $host,
'port' => $port, 'port' => $port,
'secure' => $secure, 'secure' => $secure,
'user' => $user, 'user' => $user,
'pass' => $pass, 'pass' => $pass,
)); )));
} }
/** /**

View file

@ -19,32 +19,40 @@ class Mail
/** /**
* Static properties. * Static properties.
*/ */
public static $default_transport = null; public static $default_driver = null;
public static $custom_drivers = array();
/** /**
* Set the default transport. * Set the default driver.
* *
* @param object $transport * @param object $driver
* @return void * @return void
*/ */
public static function setDefaultTransport(Drivers\MailInterface $transport) public static function setDefaultDriver(Drivers\MailInterface $driver)
{ {
self::$default_transport = $transport; self::$default_driver = $driver;
} }
/** /**
* Get the default transport. * Get the default driver.
* *
* @param object $transport * @return object
* @return void
*/ */
public static function getDefaultTransport() public static function getDefaultDriver()
{ {
if (!self::$default_transport) if (!self::$default_driver)
{ {
self::$default_transport = Drivers\Mail\MailFunction::getInstance(); self::$default_driver = Drivers\Mail\MailFunction::getInstance();
} }
return self::$default_transport; return self::$default_driver;
}
/**
* Add a custom mail driver.
*/
public static function addDriver(Drivers\MailInterface $driver)
{
self::$custom_drivers[] = $driver;
} }
/** /**
@ -64,6 +72,15 @@ class Mail
$result[] = $driver_name; $result[] = $driver_name;
} }
} }
foreach (self::$custom_drivers as $driver)
{
if ($driver->isSupported())
{
$result[] = strtolower(class_basename($driver));
}
}
$result = array_unique($result);
sort($result);
return $result; return $result;
} }
@ -73,7 +90,7 @@ class Mail
public function __construct() public function __construct()
{ {
$this->message = \Swift_Message::newInstance(); $this->message = \Swift_Message::newInstance();
$this->driver = self::getDefaultTransport(); $this->driver = self::getDefaultDriver();
} }
/** /**