Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
bbb63a5d
Commit
bbb63a5d
authored
Dec 02, 2014
by
Dave Marshall
Committed by
Fabien Potencier
Dec 13, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to disable memory spool
Conflicts: src/Silex/Provider/SwiftmailerServiceProvider.php
parent
b0edcc39
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
5 deletions
+29
-5
doc/providers/swiftmailer.rst
doc/providers/swiftmailer.rst
+10
-4
src/Silex/Provider/SwiftmailerServiceProvider.php
src/Silex/Provider/SwiftmailerServiceProvider.php
+3
-1
tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
...s/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
+16
-0
No files found.
doc/providers/swiftmailer.rst
View file @
bbb63a5d
...
@@ -10,6 +10,8 @@ will attempt to send emails through SMTP.
...
@@ -10,6 +10,8 @@ will attempt to send emails through SMTP.
Parameters
Parameters
----------
----------
* **swiftmailer.use_spool**: A boolean to specify whether or not to use the
memory spool, defaults to true.
* **swiftmailer.options**: An array of options for the default SMTP-based
* **swiftmailer.options**: An array of options for the default SMTP-based
configuration.
configuration.
...
@@ -97,13 +99,17 @@ The Swiftmailer provider provides a ``mailer`` service::
...
@@ -97,13 +99,17 @@ The Swiftmailer provider provides a ``mailer`` service::
Usage in commands
Usage in commands
~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~
T
he Swiftmailer provider sends the emails using the ``KernelEvents::TERMINATE``
By default, t
he Swiftmailer provider sends the emails using the ``KernelEvents::TERMINATE``
event, which is fired after the response has been sent. However, as this event
event, which is fired after the response has been sent. However, as this event
isn't fired for console commands, your emails won't be sent.
isn't fired for console commands, your emails won't be sent.
For that reason, if you send emails using a command console, make sure to
For that reason, if you send emails using a command console, it is recommended
flush the message spool by hand before ending the command execution. To do so,
that you disable the use of the memory spool (before accessing ``$app['mailer']``)::
use the following code::
$app['swiftmailer.use_spool'] = false;
Alternatively, you can just make sure to flush the message spool by hand before
ending the command execution. To do so, use the following code::
$app['swiftmailer.spooltransport']
$app['swiftmailer.spooltransport']
->getSpool()
->getSpool()
...
...
src/Silex/Provider/SwiftmailerServiceProvider.php
View file @
bbb63a5d
...
@@ -24,13 +24,15 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface
...
@@ -24,13 +24,15 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface
public
function
register
(
Application
$app
)
public
function
register
(
Application
$app
)
{
{
$app
[
'swiftmailer.options'
]
=
array
();
$app
[
'swiftmailer.options'
]
=
array
();
$app
[
'swiftmailer.use_spool'
]
=
true
;
$app
[
'mailer.initialized'
]
=
false
;
$app
[
'mailer.initialized'
]
=
false
;
$app
[
'mailer'
]
=
$app
->
share
(
function
(
$app
)
{
$app
[
'mailer'
]
=
$app
->
share
(
function
(
$app
)
{
$app
[
'mailer.initialized'
]
=
true
;
$app
[
'mailer.initialized'
]
=
true
;
$transport
=
$app
[
'swiftmailer.use_spool'
]
?
$app
[
'swiftmailer.spooltransport'
]
:
$app
[
'swiftmailer.transport'
];
return
new
\Swift_Mailer
(
$
app
[
'swiftmailer.spooltransport'
]
);
return
new
\Swift_Mailer
(
$
transport
);
});
});
$app
[
'swiftmailer.spooltransport'
]
=
$app
->
share
(
function
(
$app
)
{
$app
[
'swiftmailer.spooltransport'
]
=
$app
->
share
(
function
(
$app
)
{
...
...
tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
View file @
bbb63a5d
...
@@ -27,6 +27,22 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
...
@@ -27,6 +27,22 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
$this
->
assertInstanceOf
(
'Swift_Mailer'
,
$app
[
'mailer'
]);
$this
->
assertInstanceOf
(
'Swift_Mailer'
,
$app
[
'mailer'
]);
}
}
public
function
testSwiftMailerIgnoresSpoolIfDisabled
()
{
$app
=
new
Application
();
$app
->
register
(
new
SwiftmailerServiceProvider
());
$app
->
boot
();
$app
[
'swiftmailer.use_spool'
]
=
false
;
$app
[
'swiftmailer.spooltransport'
]
=
function
()
{
throw
new
\Exception
(
"Should not be instantiated"
);
};
$this
->
assertInstanceOf
(
'Swift_Mailer'
,
$app
[
'mailer'
]);
}
public
function
testSwiftMailerSendsMailsOnFinish
()
public
function
testSwiftMailerSendsMailsOnFinish
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment