Commit befa13d5 authored by Fabien Potencier's avatar Fabien Potencier

merged branch romainneutron/SwiftMailerOnTerminate (PR #316)

Commits
-------

496f6a07 E-mails are now sent after the response is sent, using the new finish filter (see #314)

Discussion
----------

E-mails are now sent after the response is sent, using the new finish filter (see #314)

This PR completes the #314 one and delays the send of emails after the response is sent.
parents f9e091fa 496f6a07
......@@ -36,7 +36,11 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface
$r = new \ReflectionClass('Swift_Mailer');
require_once dirname($r->getFilename()).'/../../swift_init.php';
return new \Swift_Mailer($app['swiftmailer.transport']);
return new \Swift_Mailer($app['swiftmailer.spooltransport']);
});
$app['swiftmailer.spooltransport'] = $app->share(function () use ($app) {
return new \Swift_SpoolTransport(new \Swift_MemorySpool());
});
$app['swiftmailer.transport'] = $app->share(function () use ($app) {
......@@ -72,6 +76,10 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface
return new \Swift_Events_SimpleEventDispatcher();
});
$app->finish(function () use ($app) {
$app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']);
});
if (isset($app['swiftmailer.class_path'])) {
require_once $app['swiftmailer.class_path'].'/Swift.php';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment