Skip to content

Commit

Permalink
Merge e6b95f5 into a394c8d
Browse files Browse the repository at this point in the history
  • Loading branch information
dol committed Sep 11, 2018
2 parents a394c8d + e6b95f5 commit 91cca69
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
67 changes: 67 additions & 0 deletions EventListener/SwiftmailerEmailSenderListener.php
@@ -0,0 +1,67 @@
<?php

/**
* Gearman Bundle for Symfony2
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Dominic Luechinger <dol+symfony@cyon.ch>
*/

namespace Mmoreram\GearmanBundle\EventListener;

use Mmoreram\GearmanBundle\GearmanEvents;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Sends emails for the memory spool.
*
* Emails are sent on the gearman.client.callback.complete event.
*
* @author Dominic Luechinger <dol+symfony@cyon.ch>
*/
class SwiftmailerEmailSenderListener implements EventSubscriberInterface
{

/**
* @var ContainerInterface
*/
private $container;

/**
* Set container
*
* @param ContainerInterface $container Container
*
* @return GearmanExecute self Object
*/
public function setContainer(ContainerInterface $container)
{
$this->container = $container;

return $this;
}

public function onComplete()
{
if (!$this->container->has('swiftmailer.email_sender.listener')) {
return;
}
$this->container->get('swiftmailer.email_sender.listener')->onTerminate();
}

/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
GearmanEvents::GEARMAN_CLIENT_CALLBACK_COMPLETE => 'onComplete',
);
}
}
5 changes: 5 additions & 0 deletions Resources/config/classes.yml
Expand Up @@ -25,6 +25,11 @@ parameters:
gearman.parser.class: Mmoreram\GearmanBundle\Service\GearmanParser
gearman.cache.wrapper.class: Mmoreram\GearmanBundle\Service\GearmanCacheWrapper

#
# EventListeners
#
gearman.swiftmailer_email_sender.listener.class: Mmoreram\GearmanBundle\EventListener\SwiftmailerEmailSenderListener

#
# Commands
#
Expand Down
8 changes: 7 additions & 1 deletion Resources/config/services.yml
Expand Up @@ -47,7 +47,13 @@ services:
parent: gearman.abstract.service
calls:
- [setContainer, ["@service_container"]]
- [setEventDispatcher, ["@event_dispatcher"]]

gearman.swiftmailer_email_sender.listener:
class: "%gearman.swiftmailer_email_sender.listener.class%"
calls:
- [setContainer, ["@service_container"]]
tags:
- { name: kernel.event_subscriber }

gearman:
class: "%gearman.client.class%"
Expand Down

0 comments on commit 91cca69

Please sign in to comment.