Skip to content

Commit

Permalink
Splitted swiftmailer configuration to avoid issues when not using smtp
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Feb 21, 2011
1 parent 52f4d81 commit e729589
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function load(array $configs, ContainerBuilder $container)
$transport = $config['transport'];
}

if ('smtp' === $transport) {
$loader->load('smtp.xml');
}

$container->setParameter('swiftmailer.transport.name', $transport);

$container->setAlias('swiftmailer.transport', 'swiftmailer.transport.'.$transport);
Expand All @@ -79,10 +83,10 @@ public function load(array $configs, ContainerBuilder $container)
if (isset($config['spool'])) {
$type = $config['spool']['type'];

$loader->load('spool.xml');
$container->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.'.$transport);
$container->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
$container->setAlias('swiftmailer.spool', 'swiftmailer.spool.'.$type);
$container->getDefinition('swiftmailer.spool.file')->setArgument(0, '%swiftmailer.spool.file.path%');

foreach (array('path') as $key) {
$container->setParameter('swiftmailer.spool.'.$type.'.'.$key, $config['spool'][$key]);
Expand Down
27 changes: 27 additions & 0 deletions src/Symfony/Bundle/SwiftmailerBundle/Resources/config/smtp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://www.symfony-project.org/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="swiftmailer.transport.smtp.class">Swift_Transport_EsmtpTransport</parameter>
</parameters>

<services>
<service id="swiftmailer.transport.smtp" class="%swiftmailer.transport.smtp.class%" public="false">
<argument type="service" id="swiftmailer.transport.buffer" />
<argument type="collection">
<argument type="service" id="swiftmailer.transport.authhandler" />
</argument>
<argument type="service" id="swiftmailer.transport.eventdispatcher" />

<call method="setHost"><argument>%swiftmailer.transport.smtp.host%</argument></call>
<call method="setPort"><argument>%swiftmailer.transport.smtp.port%</argument></call>
<call method="setEncryption"><argument>%swiftmailer.transport.smtp.encryption%</argument></call>
<call method="setUsername"><argument>%swiftmailer.transport.smtp.username%</argument></call>
<call method="setPassword"><argument>%swiftmailer.transport.smtp.password%</argument></call>
<call method="setAuthMode"><argument>%swiftmailer.transport.smtp.auth_mode%</argument></call>
</service>
</services>
</container>
26 changes: 26 additions & 0 deletions src/Symfony/Bundle/SwiftmailerBundle/Resources/config/spool.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://www.symfony-project.org/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="swiftmailer.spool.file.class">Swift_FileSpool</parameter>

<parameter key="swiftmailer.plugin.redirecting.class">Swift_Plugins_RedirectingPlugin</parameter>
<parameter key="swiftmailer.plugin.blackhole.class">Swift_Plugins_BlackholePlugin</parameter>
</parameters>

<services>
<service id="swiftmailer.transport.spool" class="Swift_Transport_SpoolTransport" public="false">
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
<argument type="service" id="swiftmailer.spool" />
</service>

<service id="swiftmailer.spool.file" class="%swiftmailer.spool.file.class%" public="false">
<argument>%swiftmailer.spool.file.path%</argument>
</service>

<service id="swiftmailer.spool" alias="swiftmailer.spool.file" public="false" />
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
<parameters>
<parameter key="swiftmailer.class">Swift_Mailer</parameter>

<parameter key="swiftmailer.transport.smtp.class">Swift_Transport_EsmtpTransport</parameter>
<parameter key="swiftmailer.transport.sendmail.class">Swift_Transport_SendmailTransport</parameter>
<parameter key="swiftmailer.transport.mail.class">Swift_Transport_MailTransport</parameter>

<parameter key="swiftmailer.transport.failover.class">Swift_Transport_FailoverTransport</parameter>
<parameter key="swiftmailer.spool.file.class">Swift_FileSpool</parameter>

<parameter key="swiftmailer.init_file">%swiftmailer.base_dir%/swift_init.php</parameter>

Expand All @@ -26,21 +24,6 @@
<file>%swiftmailer.init_file%</file>
</service>

<service id="swiftmailer.transport.smtp" class="%swiftmailer.transport.smtp.class%" public="false">
<argument type="service" id="swiftmailer.transport.buffer" />
<argument type="collection">
<argument type="service" id="swiftmailer.transport.authhandler" />
</argument>
<argument type="service" id="swiftmailer.transport.eventdispatcher" />

<call method="setHost"><argument>%swiftmailer.transport.smtp.host%</argument></call>
<call method="setPort"><argument>%swiftmailer.transport.smtp.port%</argument></call>
<call method="setEncryption"><argument>%swiftmailer.transport.smtp.encryption%</argument></call>
<call method="setUsername"><argument>%swiftmailer.transport.smtp.username%</argument></call>
<call method="setPassword"><argument>%swiftmailer.transport.smtp.password%</argument></call>
<call method="setAuthMode"><argument>%swiftmailer.transport.smtp.auth_mode%</argument></call>
</service>

<service id="swiftmailer.transport.sendmail" class="%swiftmailer.transport.sendmail.class%" public="false">
<argument type="service" id="swiftmailer.transport.buffer" />
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
Expand Down Expand Up @@ -71,27 +54,16 @@

<service id="swiftmailer.transport.replacementfactory" class="Swift_StreamFilters_StringReplacementFilterFactory" public="false" />

<service id="swiftmailer.transport.spool" class="Swift_Transport_SpoolTransport" public="false">
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
<argument type="service" id="swiftmailer.spool" />
</service>

<service id="swiftmailer.transport.null" class="Swift_Transport_NullTransport" public="false">
<argument type="service" id="swiftmailer.transport.eventdispatcher" />
</service>

<service id="swiftmailer.spool.file" class="%swiftmailer.spool.file.class%" public="false">
<argument />
</service>

<service id="swiftmailer.plugin.redirecting" class="%swiftmailer.plugin.redirecting.class%" public="false">
<argument>%swiftmailer.single_address%</argument>
</service>

<service id="swiftmailer.plugin.blackhole" class="%swiftmailer.plugin.blackhole.class%" public="false" />

<service id="swiftmailer.transport" alias="swiftmailer.transport.smtp" public="false" />

<service id="swiftmailer.spool" alias="swiftmailer.spool.file" public="false" />
</services>
</container>

0 comments on commit e729589

Please sign in to comment.