Skip to content

Commit 37265de

Browse files
committed
feature #32916 [Mailer] Add a name to the transports (fabpot)
This PR was merged into the 4.4 branch. Discussion ---------- [Mailer] Add a name to the transports | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | n/a | License | MIT | Doc PR | n/a Having a name for Transports helps identify them (useful for instance in the profiler when one uses several mailers). Commits ------- 2412dfe [Mailer] added a name to the transport
2 parents 1ce83da + 2412dfe commit 37265de

25 files changed

+191
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/MailerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function __construct(EventDispatcherInterface $eventDispatcher, LoggerInt
4242
$this->onDoSend = $onDoSend;
4343
}
4444

45+
public function getName(): string
46+
{
47+
return 'dummy://local';
48+
}
49+
4550
protected function doSend(SentMessage $message): void
4651
{
4752
$onDoSend = $this->onDoSend;

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"symfony/dom-crawler": "<4.3",
7575
"symfony/form": "<4.3",
7676
"symfony/lock": "<4.4",
77+
"symfony/mailer": "<4.4",
7778
"symfony/messenger": "<4.3",
7879
"symfony/property-info": "<3.4",
7980
"symfony/serializer": "<4.2",

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function __construct(string $accessKey, string $secretKey, string $region
4343
parent::__construct($client, $dispatcher, $logger);
4444
}
4545

46+
public function getName(): string
47+
{
48+
return sprintf('api://%s@ses?region=%s', $this->accessKey, $this->region);
49+
}
50+
4651
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4752
{
4853
$date = gmdate('D, d M Y H:i:s e');

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesHttpTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function __construct(string $accessKey, string $secretKey, string $region
4242
parent::__construct($client, $dispatcher, $logger);
4343
}
4444

45+
public function getName(): string
46+
{
47+
return sprintf('http://%s@ses?region=%s', $this->accessKey, $this->region);
48+
}
49+
4550
protected function doSendHttp(SentMessage $message): ResponseInterface
4651
{
4752
$date = gmdate('D, d M Y H:i:s e');

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3636
parent::__construct($client, $dispatcher, $logger);
3737
}
3838

39+
public function getName(): string
40+
{
41+
return sprintf('api://mandrill');
42+
}
43+
3944
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4045
{
4146
$response = $this->client->request('POST', self::ENDPOINT, [

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillHttpTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3434
parent::__construct($client, $dispatcher, $logger);
3535
}
3636

37+
public function getName(): string
38+
{
39+
return sprintf('http://mandrill');
40+
}
41+
3742
protected function doSendHttp(SentMessage $message): ResponseInterface
3843
{
3944
$envelope = $message->getEnvelope();

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public function __construct(string $key, string $domain, string $region = null,
4141
parent::__construct($client, $dispatcher, $logger);
4242
}
4343

44+
public function getName(): string
45+
{
46+
return sprintf('api://%s@mailgun?region=%s', $this->domain, $this->region);
47+
}
48+
4449
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4550
{
4651
$body = new FormDataPart($this->getPayload($email, $envelope));

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunHttpTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function __construct(string $key, string $domain, string $region = null,
4040
parent::__construct($client, $dispatcher, $logger);
4141
}
4242

43+
public function getName(): string
44+
{
45+
return sprintf('http://%s@mailgun?region=%s', $this->domain, $this->region);
46+
}
47+
4348
protected function doSendHttp(SentMessage $message): ResponseInterface
4449
{
4550
$body = new FormDataPart([

src/Symfony/Component/Mailer/Bridge/Postmark/Transport/PostmarkApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3636
parent::__construct($client, $dispatcher, $logger);
3737
}
3838

39+
public function getName(): string
40+
{
41+
return sprintf('api://postmark');
42+
}
43+
3944
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4045
{
4146
$response = $this->client->request('POST', self::ENDPOINT, [

src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3737
parent::__construct($client, $dispatcher, $logger);
3838
}
3939

40+
public function getName(): string
41+
{
42+
return sprintf('api://sendgrid');
43+
}
44+
4045
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4146
{
4247
$response = $this->client->request('POST', self::ENDPOINT, [

0 commit comments

Comments
 (0)