Procházet zdrojové kódy

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

Fabien Potencier před 14 roky
rodič
revize
b3fa8bf7cb

+ 1 - 7
src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php

@@ -49,13 +49,7 @@ class Configuration implements ConfigurationInterface
 
         $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()

+ 7 - 4
src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php

@@ -68,16 +68,19 @@ class SwiftmailerExtension extends Extension
             $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?
@@ -85,7 +88,7 @@ class SwiftmailerExtension extends Extension
             $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);
 

+ 0 - 3
src/Symfony/Bundle/SwiftmailerBundle/Tests/DependencyInjection/SwiftmailerExtensionTest.php

@@ -27,11 +27,9 @@ class SwiftmailerExtensionTest extends TestCase
         $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 @@ class SwiftmailerExtensionTest extends TestCase
         $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'));
     }