Module Configuration transport mail

This commit is contained in:
Michael RICOIS 2016-07-26 16:49:20 +02:00
parent f59c941bdb
commit 73995fa522
4 changed files with 114 additions and 0 deletions

24
module/Mailer/Module.php Normal file
View 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__,
),
),
);
}
}

View File

@ -0,0 +1,8 @@
<?php
return array(
'service_manager' => array(
'factories' => array(
'Mailer\Config' => 'Mailer\ConfigFactory',
),
),
);

View 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)
{
}
}

View 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);
}
}