Commit 8ecc11e6 authored by Dirk Luijk's avatar Dirk Luijk Committed by Fabien Potencier

Flush spool queue for console terminate as well

parent e12be31a
...@@ -14,6 +14,7 @@ namespace Silex\Provider; ...@@ -14,6 +14,7 @@ namespace Silex\Provider;
use Pimple\Container; use Pimple\Container;
use Pimple\ServiceProviderInterface; use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface; use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\PostResponseEvent; use Symfony\Component\HttpKernel\Event\PostResponseEvent;
...@@ -92,12 +93,18 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe ...@@ -92,12 +93,18 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
public function subscribe(Container $app, EventDispatcherInterface $dispatcher) public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{ {
$dispatcher->addListener(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($app) { $onTerminate = function (PostResponseEvent $event) use ($app) {
// To speed things up (by avoiding Swift Mailer initialization), flush // To speed things up (by avoiding Swift Mailer initialization), flush
// messages only if our mailer has been created (potentially used) // messages only if our mailer has been created (potentially used)
if ($app['mailer.initialized']) { if ($app['mailer.initialized']) {
$app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']); $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']);
} }
}); };
$dispatcher->addListener(KernelEvents::TERMINATE, $onTerminate);
if (class_exists('Symfony\Component\Console\ConsoleEvents')) {
$dispatcher->addListener(ConsoleEvents::TERMINATE, $onTerminate);
}
} }
} }
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