2013-11-17 22:26:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PHPCI\Helper;
|
|
|
|
|
|
|
|
|
2014-05-01 17:53:29 +02:00
|
|
|
class MailerFactory
|
|
|
|
{
|
2013-11-17 22:26:38 +01:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $emailConfig;
|
|
|
|
|
|
|
|
public function __construct($phpCiConfig = null)
|
|
|
|
{
|
|
|
|
$this->emailConfig = isset($phpCiSettings['email_settings']) ?: array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an instance of Swift_Mailer based on the config.s
|
|
|
|
* @return \Swift_Mailer
|
|
|
|
*/
|
|
|
|
public function getSwiftMailerFromConfig()
|
|
|
|
{
|
|
|
|
/** @var \Swift_SmtpTransport $transport */
|
|
|
|
$transport = \Swift_SmtpTransport::newInstance(
|
|
|
|
$this->getMailConfig('smtp_address'),
|
|
|
|
$this->getMailConfig('smtp_port'),
|
|
|
|
$this->getMailConfig('smtp_encryption')
|
|
|
|
);
|
|
|
|
$transport->setUsername($this->getMailConfig('smtp_username'));
|
|
|
|
$transport->setPassword($this->getMailConfig('smtp_password'));
|
|
|
|
|
|
|
|
return \Swift_Mailer::newInstance($transport);
|
|
|
|
}
|
|
|
|
|
2014-05-01 17:53:29 +02:00
|
|
|
protected function getMailConfig($configName)
|
2013-11-17 22:26:38 +01:00
|
|
|
{
|
|
|
|
if (isset($this->emailConfig[$configName]) && $this->emailConfig[$configName] != "") {
|
|
|
|
return $this->emailConfig[$configName];
|
|
|
|
} else {
|
|
|
|
// Check defaults
|
|
|
|
|
|
|
|
switch($configName) {
|
|
|
|
case 'smtp_address':
|
|
|
|
return "localhost";
|
|
|
|
case 'default_mailto_address':
|
|
|
|
return null;
|
|
|
|
case 'smtp_port':
|
|
|
|
return '25';
|
|
|
|
case 'smtp_encryption':
|
|
|
|
return null;
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-01 17:53:29 +02:00
|
|
|
}
|