Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd07ad3

Browse files
[Mailer] Add a way to use a custom transport
1 parent482c357 commitdd07ad3

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@ private function addMailerSection(ArrayNodeDefinition $rootNode)
15251525
->{!class_exists(FullStack::class) &&class_exists(Mailer::class) ?'canBeDisabled' :'canBeEnabled'}()
15261526
->children()
15271527
->scalarNode('dsn')->defaultValue('smtp://null')->end()
1528+
->scalarNode('transport')->defaultNull()->end()
15281529
->end()
15291530
->end()
15301531
->end()

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,11 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
19161916
}
19171917

19181918
$loader->load('mailer.xml');
1919-
$container->getDefinition('mailer.transport')->setArgument(0,$config['dsn']);
1919+
$transport =$container->getDefinition('mailer.transport');
1920+
$transport->setArgument(0,$config['dsn']);
1921+
if (null !==$config['transport']) {
1922+
$transport->setArgument(4,newReference($config['transport']));
1923+
}
19201924
}
19211925

19221926
/**

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
374374
],
375375
'mailer' => [
376376
'dsn' =>'smtp://null',
377+
'transport' =>null,
377378
'enabled' => !class_exists(FullStack::class) &&class_exists(Mailer::class),
378379
],
379380
];

‎src/Symfony/Component/Mailer/Transport.php‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
*/
3232
class Transport
3333
{
34-
publicstaticfunctionfromDsn(string$dsn,EventDispatcherInterface$dispatcher =null,HttpClientInterface$client =null,LoggerInterface$logger =null):TransportInterface
34+
publicstaticfunctionfromDsn(string$dsn,EventDispatcherInterface$dispatcher =null,HttpClientInterface$client =null,LoggerInterface$logger =null,TransportInterface$customTransport =null):TransportInterface
3535
{
3636
// failover?
3737
$dsns =preg_split('/\s++\|\|\s++/',$dsn);
3838
if (\count($dsns) >1) {
3939
$transports = [];
4040
foreach ($dsnsas$dsn) {
41-
$transports[] =self::createTransport($dsn,$dispatcher,$client,$logger);
41+
$transports[] =self::createTransport($dsn,$dispatcher,$client,$logger,$customTransport);
4242
}
4343

4444
returnnewTransport\FailoverTransport($transports);
@@ -49,16 +49,16 @@ public static function fromDsn(string $dsn, EventDispatcherInterface $dispatcher
4949
if (\count($dsns) >1) {
5050
$transports = [];
5151
foreach ($dsnsas$dsn) {
52-
$transports[] =self::createTransport($dsn,$dispatcher,$client,$logger);
52+
$transports[] =self::createTransport($dsn,$dispatcher,$client,$logger,$customTransport);
5353
}
5454

5555
returnnewTransport\RoundRobinTransport($transports);
5656
}
5757

58-
returnself::createTransport($dsn,$dispatcher,$client,$logger);
58+
returnself::createTransport($dsn,$dispatcher,$client,$logger,$customTransport);
5959
}
6060

61-
privatestaticfunctioncreateTransport(string$dsn,EventDispatcherInterface$dispatcher =null,HttpClientInterface$client =null,LoggerInterface$logger =null):TransportInterface
61+
privatestaticfunctioncreateTransport(string$dsn,EventDispatcherInterface$dispatcher =null,HttpClientInterface$client =null,LoggerInterface$logger =null,TransportInterface$customTransport =null):TransportInterface
6262
{
6363
if (false ===$parsedDsn =parse_url($dsn)) {
6464
thrownewInvalidArgumentException(sprintf('The "%s" mailer DSN is invalid.',$dsn));
@@ -169,6 +169,12 @@ private static function createTransport(string $dsn, EventDispatcherInterface $d
169169
}
170170

171171
thrownewLogicException(sprintf('The "%s" scheme is not supported for mailer "%s".',$parsedDsn['scheme'],$parsedDsn['host']));
172+
case'custom':
173+
if (!$customTransport) {
174+
thrownew \LogicException('You must specify the transport class when using the "custom" provider.');
175+
}
176+
177+
returnnew$customTransport($user,$pass,$query,$client,$dispatcher,$logger);
172178
default:
173179
if ('smtp' ===$parsedDsn['scheme']) {
174180
$transport =newTransport\Smtp\EsmtpTransport($parsedDsn['host'],$parsedDsn['port'] ??25,$query['encryption'] ??null,$query['auth_mode'] ??null,$dispatcher,$logger);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp