Permalink
Browse files

[Swiftmailer] allowed any service to be used as a transport (closes #…

…1337)
  • Loading branch information...
1 parent eacc82e commit d74768ec72842a662f8a9bd3bac182b4ca65df89 @fabpot fabpot committed Jun 15, 2011
@@ -49,13 +49,7 @@ public function getConfigTreeBuilder()
$rootNode
->children()
- ->scalarNode('transport')
- ->defaultValue('smtp')
- ->validate()
- ->ifNotInArray(array('smtp', 'mail', 'sendmail', 'gmail', null))
- ->thenInvalid('The %s transport is not supported')
- ->end()
- ->end()
+ ->scalarNode('transport')->defaultValue('smtp')->end()
->scalarNode('username')->defaultNull()->end()
->scalarNode('password')->defaultNull()->end()
->scalarNode('host')->defaultValue('localhost')->end()
@@ -68,24 +68,27 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('smtp.xml');
}
- $container->setParameter('swiftmailer.transport.name', $transport);
+ if (in_array($transport, array('smtp', 'mail', 'sendmail', 'null'))) {
+ // built-in transport
+ $transport = 'swiftmailer.transport.'.$transport;
+ }
- $container->setAlias('swiftmailer.transport', 'swiftmailer.transport.'.$transport);
+ $container->setAlias('swiftmailer.transport', $transport);
if (false === $config['port']) {
$config['port'] = 'ssl' === $config['encryption'] ? 465 : 25;
}
foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) {
- $container->setParameter('swiftmailer.transport.'.$transport.'.'.$key, $config[$key]);
+ $container->setParameter('swiftmailer.transport.smtp.'.$key, $config[$key]);
}
// spool?
if (isset($config['spool'])) {
$type = $config['spool']['type'];
$loader->load('spool.xml');
- $container->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.'.$transport);
+ $container->setAlias('swiftmailer.transport.real', $transport);
$container->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
$container->setAlias('swiftmailer.spool', 'swiftmailer.spool.'.$type);
@@ -27,11 +27,9 @@ public function testConfigLoad()
$this->assertEquals('Swift_Mailer', $container->getParameter('swiftmailer.class'), '->load() loads the swiftmailer.xml file if not already loaded');
$loader->load(array(array('transport' => 'sendmail')), $container);
- $this->assertEquals('sendmail', $container->getParameter('swiftmailer.transport.name'), '->load() overrides existing configuration options');
$this->assertEquals('swiftmailer.transport.sendmail', (string) $container->getAlias('swiftmailer.transport'));
$loader->load(array(array()), $container);
- $this->assertEquals('smtp', $container->getParameter('swiftmailer.transport.name'), '->load() provides default values for configuration options');
$this->assertEquals('swiftmailer.transport.smtp', (string) $container->getAlias('swiftmailer.transport'));
}
@@ -42,7 +40,6 @@ public function testNullTransport()
$loader = new SwiftmailerExtension();
$loader->load(array(array('transport' => null)), $container);
- $this->assertEquals('null', $container->getParameter('swiftmailer.transport.name'), '->load() uses the "null" string transport when transport is null');
$this->assertEquals('swiftmailer.transport.null', (string) $container->getAlias('swiftmailer.transport'));
}

0 comments on commit d74768e

Please sign in to comment.