Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Swiftmailer] added the swiftmailer.plugin tag to automatically regis…

…ter Swiftmailer plugins
  • Loading branch information...
commit 483dcf77dff7eecc25feda8ec5ad1c5953c01a6c 1 parent 1a7629b
@fabpot fabpot authored
View
36 DependencyInjection/Compiler/RegisterPluginsPass.php
@@ -0,0 +1,36 @@
+<?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\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->hasDefinition('swiftmailer.mailer')) {
+ return;
+ }
+
+ $definition = $container->findDefinition('swiftmailer.transport');
+ foreach ($container->findTaggedServiceIds('swiftmailer.plugin') as $id => $args) {
+ $definition->addMethodCall('registerPlugin', array(new Reference($id)));
+ }
+ }
+}
View
10 DependencyInjection/SwiftmailerExtension.php
@@ -96,30 +96,30 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('swiftmailer.plugin.antiflood.threshold', $config['antiflood']['threshold']);
$container->setParameter('swiftmailer.plugin.antiflood.sleep', $config['antiflood']['sleep']);
- $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.antiflood')));
+ $container->getDefinition('swiftmailer.plugin.antiflood')->addTag('swiftmailer.plugin');
}
if ($config['logging']) {
- $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.messagelogger')));
+ $container->getDefinition('swiftmailer.plugin.messagelogger')->addTag('swiftmailer.plugin');
$container->findDefinition('swiftmailer.data_collector')->addTag('data_collector', array('template' => 'SwiftmailerBundle:Collector:swiftmailer', 'id' => 'swiftmailer'));
}
if (isset($config['sender_address']) && $config['sender_address']) {
$container->setParameter('swiftmailer.sender_address', $config['sender_address']);
- $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.impersonate')));
+ $container->getDefinition('swiftmailer.plugin.impersonate')->addTag('swiftmailer.plugin');
} else {
$container->setParameter('swiftmailer.sender_address', null);
}
if (isset($config['delivery_address']) && $config['delivery_address']) {
$container->setParameter('swiftmailer.single_address', $config['delivery_address']);
- $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting')));
+ $container->getDefinition('swiftmailer.plugin.redirecting')->addTag('swiftmailer.plugin');
} else {
$container->setParameter('swiftmailer.single_address', null);
}
if (isset($config['disable_delivery']) && $config['disable_delivery']) {
- $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.blackhole')));
+ $container->getDefinition('swiftmailer.plugin.blackhole')->addTag('swiftmailer.plugin');
}
}
View
4 Resources/config/swiftmailer.xml
@@ -67,7 +67,7 @@
</service>
<service id="swiftmailer.plugin.blackhole" class="%swiftmailer.plugin.blackhole.class%" public="false" />
-
+
<service id="swiftmailer.plugin.antiflood" class="%swiftmailer.plugin.antiflood.class%" public="false">
<argument>%swiftmailer.plugin.antiflood.threshold%</argument>
<argument>%swiftmailer.plugin.antiflood.sleep%</argument>
@@ -76,7 +76,7 @@
<service id="swiftmailer.plugin.impersonate" class="%swiftmailer.plugin.impersonate.class%" public="false">
<argument>%swiftmailer.sender_address%</argument>
</service>
-
+
<service id="swiftmailer.plugin.messagelogger" class="%swiftmailer.plugin.messagelogger.class%" />
<service id="swiftmailer.data_collector" class="%swiftmailer.data_collector.class%" public="false">
View
8 SwiftmailerBundle.php
@@ -12,6 +12,8 @@
namespace Symfony\Bundle\SwiftmailerBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Bundle\SwiftmailerBundle\DependencyInjection\Compiler\RegisterPluginsPass;
/**
* Bundle.
@@ -20,4 +22,10 @@
*/
class SwiftmailerBundle extends Bundle
{
+ public function build(ContainerBuilder $container)
+ {
+ parent::build($container);
+
+ $container->addCompilerPass(new RegisterPluginsPass());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.