Commit 6f99eb8e authored by Fabien Potencier's avatar Fabien Potencier

fixed the previous merged (private properties are not accessible in the closures)

parent ef9398de
......@@ -21,15 +21,15 @@ use Silex\ServiceProviderInterface;
*/
class SwiftmailerServiceProvider implements ServiceProviderInterface
{
private $mailerCreated;
public function register(Application $app)
{
$app['swiftmailer.options'] = array();
$self = $this;
$app['mailer'] = $app->share(function () use ($app, $self) {
$self->mailerCreated = true;
$app['mailer.initialized'] = false;
$app['mailer'] = $app->share(function () use ($app) {
$app['mailer.initialized'] = true;
return new \Swift_Mailer($app['swiftmailer.spooltransport']);
});
......@@ -91,11 +91,10 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface
throw new \RuntimeException('You have provided the swiftmailer.class_path parameter. The autoloader has been removed from Silex. It is recommended that you use Composer to manage your dependencies and handle your autoloading. If you are already using Composer, you can remove the parameter. See http://getcomposer.org for more information.');
}
$self = $this;
$app->finish(function () use ($app, $self) {
//To speed things up (by avoiding Swift Mailer initialization), flush
//messages only if our mailer has been created (potentially used)
if ($self->mailerCreated) {
$app->finish(function () use ($app) {
// To speed things up (by avoiding Swift Mailer initialization), flush
// messages only if our mailer has been created (potentially used)
if ($app['mailer.initialized']) {
$app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']);
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment