Module Configuration transport mail
This commit is contained in:
parent
f59c941bdb
commit
73995fa522
24
module/Mailer/Module.php
Normal file
24
module/Mailer/Module.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Mailer;
|
||||
|
||||
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
|
||||
use Zend\ModuleManager\Feature\ConfigProviderInterface;
|
||||
|
||||
class Module implements AutoloaderProviderInterface, ConfigProviderInterface
|
||||
{
|
||||
public function getConfig()
|
||||
{
|
||||
return include __DIR__ . '/config/module.config.php';
|
||||
}
|
||||
|
||||
public function getAutoloaderConfig()
|
||||
{
|
||||
return array(
|
||||
'Zend\Loader\StandardAutoloader' => array(
|
||||
'namespaces' => array(
|
||||
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
8
module/Mailer/config/module.config.php
Normal file
8
module/Mailer/config/module.config.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
return array(
|
||||
'service_manager' => array(
|
||||
'factories' => array(
|
||||
'Mailer\Config' => 'Mailer\ConfigFactory',
|
||||
),
|
||||
),
|
||||
);
|
60
module/Mailer/src/Mailer/Config.php
Normal file
60
module/Mailer/src/Mailer/Config.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Mailer;
|
||||
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
* @var array associative array represents app config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Mailer to configure transport
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Transport Mailer
|
||||
* @return \Swift_Transport
|
||||
*/
|
||||
public function getTransportConfigure()
|
||||
{
|
||||
switch ($this->config['method']) {
|
||||
case 'sendmail':
|
||||
$tr = \Swift_SendmailTransport::newInstance();
|
||||
break;
|
||||
case 'smtp':
|
||||
$tr = \Swift_SmtpTransport::newInstance();
|
||||
if (array_key_exists('port', $this->config)) {
|
||||
$tr->setPort($this->config['port']);
|
||||
}
|
||||
if (array_key_exists('host', $this->config)) {
|
||||
$tr->setHost($this->config['host']);
|
||||
}
|
||||
if (array_key_exists('username', $this->config)) {
|
||||
$tr->setUsername($this->config['username']);
|
||||
}
|
||||
if (array_key_exists('password', $this->config)) {
|
||||
$tr->setPassword($this->config('password'));
|
||||
}
|
||||
if (array_key_exists('authmode', $this->config)) {
|
||||
$tr->setAuthMode($mode);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$tr = \Swift_MailTransport::newInstance();
|
||||
break;
|
||||
}
|
||||
|
||||
return $tr;
|
||||
}
|
||||
|
||||
public function getMailFromKey(string $name)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
22
module/Mailer/src/Mailer/ConfigFactory.php
Normal file
22
module/Mailer/src/Mailer/ConfigFactory.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Mailer;
|
||||
|
||||
use Zend\ServiceManager\FactoryInterface;
|
||||
use Zend\ServiceManager\ServiceLocatorInterface;
|
||||
|
||||
class ConfigFactory implements FactoryInterface
|
||||
{
|
||||
public function createService(ServiceLocatorInterface $serviceLocator)
|
||||
{
|
||||
$serviceLocator = $serviceLocator->getServiceLocator();
|
||||
$appConfig = $serviceLocator->get('config');
|
||||
|
||||
$config = array();
|
||||
if (array_key_exists('mailer', $appConfig)) {
|
||||
$config = $appConfig['mailer'];
|
||||
}
|
||||
|
||||
return new Config($config);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user