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
f1b4cc86
Commit
f1b4cc86
authored
Nov 29, 2016
by
Christian Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for SwiftMailer plugins
parent
57aea820
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
16 deletions
+79
-16
doc/providers/swiftmailer.rst
doc/providers/swiftmailer.rst
+10
-0
src/Silex/Provider/SwiftmailerServiceProvider.php
src/Silex/Provider/SwiftmailerServiceProvider.php
+27
-15
tests/Silex/Tests/Provider/SpoolStub.php
tests/Silex/Tests/Provider/SpoolStub.php
+1
-1
tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
...s/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
+41
-0
No files found.
doc/providers/swiftmailer.rst
View file @
f1b4cc86
...
...
@@ -47,6 +47,16 @@ Parameters
``delivery_addresses``. If set, emails matching any of these patterns will be
delivered like normal, as well as being sent to ``delivery_addresses``.
* **swiftmailer.plugins**: Array of SwiftMailer plugins.
Example usage::
$app['swiftmailer.plugins'] = function ($app) {
return array(
new \Swift_Plugins_PopBeforeSmtpPlugin('pop3.example.com'),
);
};
Services
--------
...
...
src/Silex/Provider/SwiftmailerServiceProvider.php
View file @
f1b4cc86
...
...
@@ -71,17 +71,6 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
$transport
->
setPassword
(
$options
[
'password'
]);
$transport
->
setAuthMode
(
$options
[
'auth_mode'
]);
if
(
null
!==
$app
[
'swiftmailer.sender_address'
])
{
$transport
->
registerPlugin
(
new
\Swift_Plugins_ImpersonatePlugin
(
$app
[
'swiftmailer.sender_address'
]));
}
if
(
!
empty
(
$app
[
'swiftmailer.delivery_addresses'
]))
{
$transport
->
registerPlugin
(
new
\Swift_Plugins_RedirectingPlugin
(
$app
[
'swiftmailer.delivery_addresses'
],
$app
[
'swiftmailer.delivery_whitelist'
]
));
}
return
$transport
;
};
...
...
@@ -97,13 +86,36 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
));
};
$app
[
'swiftmailer.transport.eventdispatcher'
]
=
function
()
{
return
new
\Swift_Events_SimpleEventDispatcher
();
$app
[
'swiftmailer.transport.eventdispatcher'
]
=
function
(
$app
)
{
$dispatcher
=
new
\Swift_Events_SimpleEventDispatcher
();
$plugins
=
$app
[
'swiftmailer.plugins'
];
if
(
null
!==
$app
[
'swiftmailer.sender_address'
])
{
$plugins
[]
=
new
\Swift_Plugins_ImpersonatePlugin
(
$app
[
'swiftmailer.sender_address'
]);
}
if
(
!
empty
(
$app
[
'swiftmailer.delivery_addresses'
]))
{
$plugins
[]
=
new
\Swift_Plugins_RedirectingPlugin
(
$app
[
'swiftmailer.delivery_addresses'
],
$app
[
'swiftmailer.delivery_whitelist'
]
);
}
foreach
(
$plugins
as
$plugin
)
{
$dispatcher
->
bindEventListener
(
$plugin
);
}
return
$dispatcher
;
};
$app
[
'swiftmailer.plugins'
]
=
function
(
$app
)
{
return
array
();
};
$app
[
'swiftmailer.sender_address'
]
=
null
;
$app
[
'swiftmailer.delivery_addresses'
]
=
[]
;
$app
[
'swiftmailer.delivery_whitelist'
]
=
[]
;
$app
[
'swiftmailer.delivery_addresses'
]
=
array
()
;
$app
[
'swiftmailer.delivery_whitelist'
]
=
array
()
;
}
public
function
subscribe
(
Container
$app
,
EventDispatcherInterface
$dispatcher
)
...
...
tests/Silex/Tests/Provider/SpoolStub.php
View file @
f1b4cc86
...
...
@@ -36,7 +36,7 @@ class SpoolStub implements \Swift_Spool
public
function
queueMessage
(
\Swift_Mime_Message
$message
)
{
$this
->
messages
[]
=
$message
;
$this
->
messages
[]
=
clone
$message
;
}
public
function
flushQueue
(
\Swift_Transport
$transport
,
&
$failedRecipients
=
null
)
...
...
tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
View file @
f1b4cc86
...
...
@@ -89,4 +89,45 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
$app
->
terminate
(
$request
,
$response
);
$this
->
assertFalse
(
$app
[
'swiftmailer.spool'
]
->
hasFlushed
);
}
public
function
testSwiftMailerSenderAddress
()
{
$app
=
new
Application
();
$app
->
register
(
new
SwiftmailerServiceProvider
());
$app
->
boot
();
$app
[
'swiftmailer.spool'
]
=
function
()
{
return
new
SpoolStub
();
};
$app
[
'swiftmailer.sender_address'
]
=
'foo@example.com'
;
$app
[
'mailer'
]
->
send
(
\Swift_Message
::
newInstance
());
$messages
=
$app
[
'swiftmailer.spool'
]
->
getMessages
();
$this
->
assertCount
(
1
,
$messages
);
list
(
$message
)
=
$messages
;
$this
->
assertEquals
(
'foo@example.com'
,
$message
->
getReturnPath
());
}
public
function
testSwiftMailerPlugins
()
{
$plugin
=
$this
->
getMockBuilder
(
'Swift_Events_TransportChangeListener'
)
->
getMock
();
$plugin
->
expects
(
$this
->
once
())
->
method
(
'beforeTransportStarted'
);
$app
=
new
Application
();
$app
->
boot
();
$app
->
register
(
new
SwiftmailerServiceProvider
());
$app
[
'swiftmailer.plugins'
]
=
function
(
$app
)
use
(
$plugin
)
{
return
array
(
$plugin
);
};
$dispatcher
=
$app
[
'swiftmailer.transport.eventdispatcher'
];
$event
=
$dispatcher
->
createTransportChangeEvent
(
new
\Swift_Transport_NullTransport
(
$dispatcher
));
$dispatcher
->
dispatchEvent
(
$event
,
'beforeTransportStarted'
);
}
}
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