-
-
Notifications
You must be signed in to change notification settings - Fork 154
allow using env variables in transport configuration #159
Conversation
1a70e60
to
69a961d
Compare
// Deprecate url | ||
->beforeNormalization() | ||
->ifTrue(function ($v) { | ||
return is_array($v) && array_key_exists('url', $v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& !array_key_exists('dsn', $v)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will keep this condition to keep the trigger_error
anyway, but check if dsn
is already set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why renaming the config key to expose the same feature ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
@@ -11,6 +11,7 @@ | |||
|
|||
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection; | |||
|
|||
use Symfony\Component\DependencyInjection\Definition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be moved below, alpha order in the "DependencyInjection" group
* | ||
* @return string transport | ||
*/ | ||
public static function resolveOptions(array &$options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of passing this by reference, I'd make the function return $options, with $options['transport']
always set
*/ | ||
public static function resolveOptions(array &$options) | ||
{ | ||
if (null === $options['transport']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!isset($options['transport'])
now that the code is "public"
|
||
if (isset($options['dsn'])) { | ||
$parts = parse_url($options['dsn']); | ||
if (!empty($parts['scheme'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use isset everywhere
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name), $definitionDecorator) | ||
; | ||
|
||
$options = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not need for this line
; | ||
|
||
$options = []; | ||
$container->resolveEnvPlaceholders($mailer, null, $options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/$options/$usedEnvs/
$options = []; | ||
$container->resolveEnvPlaceholders($mailer, null, $options); | ||
|
||
if ($options && isset($mailer['dsn'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the && isset($mailer['dsn'])
part, isn't it?
->replaceArgument(0, new Reference(sprintf('swiftmailer.mailer.%s.transport', $name))) | ||
; | ||
|
||
$enable = !(isset($mailer['disable_delivery']) && $mailer['disable_delivery']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isset(foo) && foo is the same as !empty(foo)
if (!empty($query['auth_mode'])) { | ||
$mailer['auth_mode'] = $query['auth_mode']; | ||
} | ||
if (isset($mailer['disable_delivery']) && $mailer['disable_delivery']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty
19ebd3a
to
b39da7a
Compare
LGTM. We should just make this work on 5.3 since that's the minimum version. |
73d2ec3
to
e1975b5
Compare
0bb8f42
to
183b291
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you @mykiwi. |
…kiwi) This PR was merged into the 2.5-dev branch. Discussion ---------- allow using env variables in transport configuration Example: ```yml # MAILER_URL=transport://user:pass@host:port/?encryption=...&auth_mode=... swiftmailer: url: "%env(MAILER_URL)%" ``` To do: - [x] add the doc symfony/symfony-docs/pull/7510 - [x] add tests Commits ------- 183b291 allow using env variables in transport configuration
While testing this PR, I noticed that 2 configurations cannot be used as env vars: |
This breaks some tests for me... We have tests checking if a mail was sent, which is done as described in http://symfony.com/doc/current/email/testing.html. We've also added a configuration to the config: swiftmailer:
disable_delivery: true But somehow this seems not to be considered anymore. Swiftmailer throws an error at https://github.com/swiftmailer/swiftmailer/blob/c5bd821/lib/classes/Swift/Transport/StreamBuffer.php#L268 I guess this is connected to this PR, because it is working with version 2.4.2 of this bundle, but not anymore with 2.5. Any configuration I am missing now? |
@mykiwi It has to be connected somehow... This PR is the only being merged in 2.5.0. |
@mykiwi We have another report for the exact same issue, so it is definitely a problem related to the changes done here. Can you investigate? |
Regarding |
It works for me again when I set the configuration as follows: swiftmailer:
disable_delivery: true
transport: "null" Mind that |
…luz) This PR was merged into the master branch. Discussion ---------- [SwiftMailer] Update future reference - [x] Require symfony/swiftmailer-bundle#159 Commits ------- 6aa0117 Removed "encryption" and "auth_mode" from the list of %env()% compatible options 76ce6af Fixed ... again ... the versionadded directives ef7536c Added the missing "versionadded" directives 635a0ab add mail transport as deprecated 54ad41c Minor tweaks 287b71f update swiftmailer reference
Example:
To do: