@@ -31,16 +31,16 @@ class SwiftmailerTransportFactory
31
31
*/
32
32
public static function createTransport (array $ options , RequestContext $ requestContext , \Swift_Events_EventDispatcher $ eventDispatcher )
33
33
{
34
- $ transport = static ::resolveOptions ($ options );
34
+ $ options = static ::resolveOptions ($ options );
35
35
36
- if ('smtp ' === $ transport ) {
36
+ if ('smtp ' === $ options [ ' transport ' ] ) {
37
37
$ smtpAuthHandler = new \Swift_Transport_Esmtp_AuthHandler ([
38
38
new \Swift_Transport_Esmtp_Auth_CramMd5Authenticator (),
39
39
new \Swift_Transport_Esmtp_Auth_LoginAuthenticator (),
40
40
new \Swift_Transport_Esmtp_Auth_PlainAuthenticator (),
41
41
]);
42
- $ smtpAuthHandler ->setUsername ($ options ['user ' ]);
43
- $ smtpAuthHandler ->setPassword ($ options ['pass ' ]);
42
+ $ smtpAuthHandler ->setUsername ($ options ['username ' ]);
43
+ $ smtpAuthHandler ->setPassword ($ options ['password ' ]);
44
44
$ smtpAuthHandler ->setAuthMode ($ options ['auth_mode ' ]);
45
45
46
46
$ transport = new \Swift_Transport_EsmtpTransport (
@@ -55,22 +55,22 @@ public static function createTransport(array $options, RequestContext $requestCo
55
55
$ transport ->setSourceIp ($ options ['source_ip ' ]);
56
56
57
57
(new SmtpTransportConfigurator (null , $ requestContext ))->configure ($ transport );
58
- } elseif ('sendmail ' === $ transport ) {
58
+ } elseif ('sendmail ' === $ options [ ' transport ' ] ) {
59
59
$ transport = new \Swift_Transport_SendmailTransport (
60
60
new \Swift_Transport_StreamBuffer (new \Swift_StreamFilters_StringReplacementFilterFactory ()),
61
61
$ eventDispatcher
62
62
);
63
63
64
64
(new SmtpTransportConfigurator (null , $ requestContext ))->configure ($ transport );
65
- } elseif ('mail ' === $ transport ) {
65
+ } elseif ('mail ' === $ options [ ' transport ' ] ) {
66
66
$ transport = new \Swift_Transport_MailTransport (
67
67
new \Swift_Transport_SimpleMailInvoker (),
68
68
$ eventDispatcher
69
69
);
70
- } elseif ('null ' === $ transport ) {
70
+ } elseif ('null ' === $ options [ ' transport ' ] ) {
71
71
$ transport = new \Swift_Transport_NullTransport ($ eventDispatcher );
72
72
} else {
73
- throw new \InvalidArgumentException (sprintf ('Not a built-in Swiftmailer transport: %s. ' , $ options ['dsn ' ]));
73
+ throw new \InvalidArgumentException (sprintf ('Not a built-in Swiftmailer transport: %s. ' , $ options ['transport ' ]));
74
74
}
75
75
76
76
return $ transport ;
@@ -79,60 +79,52 @@ public static function createTransport(array $options, RequestContext $requestCo
79
79
/**
80
80
* @param array $options
81
81
*
82
- * @return string transport
82
+ * @return array options
83
83
*/
84
- public static function resolveOptions (array & $ options )
84
+ public static function resolveOptions (array $ options )
85
85
{
86
86
if (null === $ options ['transport ' ]) {
87
- $ transport = 'null ' ;
87
+ $ options [ ' transport ' ] = 'null ' ;
88
88
} elseif ('gmail ' === $ options ['transport ' ]) {
89
89
$ options ['encryption ' ] = 'ssl ' ;
90
90
$ options ['auth_mode ' ] = 'login ' ;
91
91
$ options ['host ' ] = 'smtp.gmail.com ' ;
92
- $ transport = 'smtp ' ;
93
- } else {
94
- $ transport = $ options ['transport ' ];
92
+ $ options ['transport ' ] = 'smtp ' ;
95
93
}
96
94
97
95
if (isset ($ options ['dsn ' ])) {
98
96
$ parts = parse_url ($ options ['dsn ' ]);
99
- if (!empty ($ parts ['scheme ' ])) {
100
- $ transport = $ parts ['scheme ' ];
97
+ if (!isset ($ parts ['scheme ' ])) {
98
+ $ options [ ' transport ' ] = $ parts ['scheme ' ];
101
99
}
102
-
103
- if (!empty ($ parts ['user ' ])) {
100
+ if (!isset ($ parts ['user ' ])) {
104
101
$ options ['username ' ] = $ parts ['user ' ];
105
102
}
106
- if (!empty ($ parts ['pass ' ])) {
103
+ if (!isset ($ parts ['pass ' ])) {
107
104
$ options ['password ' ] = $ parts ['pass ' ];
108
105
}
109
- if (!empty ($ parts ['host ' ])) {
106
+ if (!isset ($ parts ['host ' ])) {
110
107
$ options ['host ' ] = $ parts ['host ' ];
111
108
}
112
- if (!empty ($ parts ['port ' ])) {
109
+ if (!isset ($ parts ['port ' ])) {
113
110
$ options ['port ' ] = $ parts ['port ' ];
114
111
}
115
- if (!empty ($ parts ['query ' ])) {
116
- $ query = [];
112
+ if (!isset ($ parts ['query ' ])) {
117
113
parse_str ($ parts ['query ' ], $ query );
118
- if (!empty ($ query ['encryption ' ])) {
119
- $ options ['encryption ' ] = $ query ['encryption ' ];
120
- }
121
- if (!empty ($ query ['auth_mode ' ])) {
122
- $ options ['auth_mode ' ] = $ query ['auth_mode ' ];
123
- }
124
- if (!empty ($ query ['timeout ' ])) {
125
- $ options ['timeout ' ] = $ query ['timeout ' ];
126
- }
127
- if (!empty ($ query ['source_ip ' ])) {
128
- $ options ['source_ip ' ] = $ query ['source_ip ' ];
129
- }
130
- if (!empty ($ query ['local_domain ' ])) {
131
- $ options ['local_domain ' ] = $ query ['local_domain ' ];
114
+ $ values = array ('encryption ' => null , 'auth_mode ' => null , 'timeout ' => null , 'source_ip ' => null , 'local_domain ' => null );
115
+ foreach ($ values as $ key => $ value ) {
116
+ if (!isset ($ query [$ key ])) {
117
+ $ values [$ key ] = $ query [$ key ];
118
+ }
132
119
}
120
+ $ options += $ values ;
133
121
}
134
122
}
135
123
136
- return $ transport ;
124
+ if (isset ($ options ['port ' ])) {
125
+ $ options ['port ' ] = 'ssl ' === $ options ['encryption ' ] ? 465 : 25 ;
126
+ }
127
+
128
+ return $ options ;
137
129
}
138
130
}
0 commit comments