Source of file EmailSenderListener.php
Size: 1,698 Bytes - Last Modified: 2013-05-15T10:38:58+02:00
/home/theseer/Downloads/Symfony/vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/EventListener/EmailSenderListener.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | <?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bundle\SwiftmailerBundle\EventListener; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\IntrospectableContainerInterface; use Symfony\Component\HttpKernel\Event\PostResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Sends emails for the memory spool. * * Emails are sent on the kernel.terminate event. * * @author Fabien Potencier <fabien@symfony.com> */ class EmailSenderListener implements EventSubscriberInterface { private $container; public function __construct(ContainerInterface $container) { $this->container = $container; } public function onKernelTerminate(PostResponseEvent $event) { if ($this->container instanceof IntrospectableContainerInterface && !$this->container->initialized('mailer')) { return; } $transport = $this->container->get('mailer')->getTransport(); if (!$transport instanceof \Swift_Transport_SpoolTransport) { return; } $spool = $transport->getSpool(); if (!$spool instanceof \Swift_MemorySpool) { return; } $spool->flushQueue($this->container->get('swiftmailer.transport.real')); } static public function getSubscribedEvents() { return array(KernelEvents::TERMINATE => 'onKernelTerminate'); } } |