31
31
*/
32
32
class Transport
33
33
{
34
- public static function fromDsn (string $ dsn , EventDispatcherInterface $ dispatcher = null , HttpClientInterface $ client = null , LoggerInterface $ logger = null ): TransportInterface
34
+ public static function fromDsn (string $ dsn , EventDispatcherInterface $ dispatcher = null , HttpClientInterface $ client = null , LoggerInterface $ logger = null , TransportInterface $ customTransport = null ): TransportInterface
35
35
{
36
36
// failover?
37
37
$ dsns = preg_split ('/\s++\|\|\s++/ ' , $ dsn );
38
38
if (\count ($ dsns ) > 1 ) {
39
39
$ transports = [];
40
40
foreach ($ dsns as $ dsn ) {
41
- $ transports [] = self ::createTransport ($ dsn , $ dispatcher , $ client , $ logger );
41
+ $ transports [] = self ::createTransport ($ dsn , $ dispatcher , $ client , $ logger, $ customTransport );
42
42
}
43
43
44
44
return new Transport \FailoverTransport ($ transports );
@@ -49,16 +49,16 @@ public static function fromDsn(string $dsn, EventDispatcherInterface $dispatcher
49
49
if (\count ($ dsns ) > 1 ) {
50
50
$ transports = [];
51
51
foreach ($ dsns as $ dsn ) {
52
- $ transports [] = self ::createTransport ($ dsn , $ dispatcher , $ client , $ logger );
52
+ $ transports [] = self ::createTransport ($ dsn , $ dispatcher , $ client , $ logger, $ customTransport );
53
53
}
54
54
55
55
return new Transport \RoundRobinTransport ($ transports );
56
56
}
57
57
58
- return self ::createTransport ($ dsn , $ dispatcher , $ client , $ logger );
58
+ return self ::createTransport ($ dsn , $ dispatcher , $ client , $ logger, $ customTransport );
59
59
}
60
60
61
- private static function createTransport (string $ dsn , EventDispatcherInterface $ dispatcher = null , HttpClientInterface $ client = null , LoggerInterface $ logger = null ): TransportInterface
61
+ private static function createTransport (string $ dsn , EventDispatcherInterface $ dispatcher = null , HttpClientInterface $ client = null , LoggerInterface $ logger = null , TransportInterface $ customTransport = null ): TransportInterface
62
62
{
63
63
if (false === $ parsedDsn = parse_url ($ dsn )) {
64
64
throw new InvalidArgumentException (sprintf ('The "%s" mailer DSN is invalid. ' , $ dsn ));
@@ -169,6 +169,12 @@ private static function createTransport(string $dsn, EventDispatcherInterface $d
169
169
}
170
170
171
171
throw new LogicException (sprintf ('The "%s" scheme is not supported for mailer "%s". ' , $ parsedDsn ['scheme ' ], $ parsedDsn ['host ' ]));
172
+ case 'custom ' :
173
+ if (!$ customTransport ) {
174
+ throw new \LogicException ('You must specify the transport class when using the "custom" provider. ' );
175
+ }
176
+
177
+ return new $ customTransport ($ user , $ pass , $ query , $ client , $ dispatcher , $ logger );
172
178
default :
173
179
if ('smtp ' === $ parsedDsn ['scheme ' ]) {
174
180
$ transport = new Transport \Smtp \EsmtpTransport ($ parsedDsn ['host ' ], $ parsedDsn ['port ' ] ?? 25 , $ query ['encryption ' ] ?? null , $ query ['auth_mode ' ] ?? null , $ dispatcher , $ logger );
0 commit comments