Here's some quick sample code to try and explain what I'm experiencing:
Code: Select all
<?php
require_once '../lib/Swift/swift_required.php';
$emailer_1 = new Swift_Mailer(new Swift_SmtpTransport('localhost'));
print_r($emailer_1);
$emailer_1->registerPlugin(new Swift_Plugins_LoggerPlugin(new Swift_Plugins_Loggers_ArrayLogger()));
$emailer_2 = new Swift_Mailer(new Swift_SmtpTransport('localhost'));
print_r($emailer_2);What I am trying to do in my application is send emails for orders that meet certain conditions. As I iterate through the orders, if the order needs an email sent, it goes off and creates it's own Swift_Mailer. Unfortunately, it seems that it is inheriting the mailer settings of other orders, which won't work for me. Specifically, the LoggerPlugin I use is passed the trigger criteria of the order and it goes off to see if that order was already triggered (preventing duplicate emails). If the LoggerPlugin is reused, the criteria it is passed never gets updated (since it is passed at creation).
Anyone have any ideas for a fix or workaround?
EDIT: So I found the dependencies being used/created and see where the problem exists. The first instance of Swift_Mailer (Swift_Transport really) registers the listeners to transport.eventdispatcher, so then in the future if any new Swift_Transport comes along, it has to use that dispatcher too. Adding an additional plugin does not overwrite, but just appends to the array of existing plugins. Just your typical global variable problem I guess. Since there is no way to remove a plugins (viewtopic.php?f=52&t=95441&p=521160#p521160) or reset the dependencies, I don't think there is a frontend fix to this... Here's some new code just for reference:
Code: Select all
<?php
require_once '../lib/Swift/swift_required.php';
print_r(
Swift_DependencyContainer::getInstance()
->lookup('transport.eventdispatcher')
);
$emailer_1 = new Swift_Mailer(new Swift_SmtpTransport('localhost'));
$emailer_1->registerPlugin(new Swift_Plugins_LoggerPlugin(new Swift_Plugins_Loggers_ArrayLogger()));
$emailer_2 = new Swift_Mailer(new Swift_SmtpTransport('localhost'));
print_r(
Swift_DependencyContainer::getInstance()
->lookup('transport.eventdispatcher')
);
$emailer_2->registerPlugin(new Swift_Plugins_LoggerPlugin(new Swift_Plugins_Loggers_ArrayLogger()));
print_r(
Swift_DependencyContainer::getInstance()
->lookup('transport.eventdispatcher')
);