Skip to content

Instantly share code, notes, and snippets.

@kkasprzak
Created November 25, 2013 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkasprzak/7641316 to your computer and use it in GitHub Desktop.
Save kkasprzak/7641316 to your computer and use it in GitHub Desktop.
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
/**
* RegisterPluginsPass registers Swiftmailer plugins.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RegisterPluginsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->findDefinition('swiftmailer.mailer') || !$container->getParameter('swiftmailer.mailers')) {
return;
}
$mailers = $container->getParameter('swiftmailer.mailers');
foreach ($mailers as $name => $mailer) {
$plugins = $container->findTaggedServiceIds(sprintf('swiftmailer.%s.plugin', $name));
$transport = sprintf('swiftmailer.mailer.%s.transport', $name);
$definition = $container->findDefinition($transport);
foreach ($plugins as $id => $args) {
$definition->addMethodCall('registerPlugin', array(new Reference($id)));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment