Skip to content

Commit 413cc60

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 ------- 2412dfe71f [Mailer] added a name to the transport
2 parents 2f9740b + c5ebce0 commit 413cc60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+378
-0
lines changed

AbstractTransport.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function __construct(EventDispatcherInterface $dispatcher = null, LoggerI
3939
$this->logger = $logger ?: new NullLogger();
4040
}
4141

42+
abstract public function getName(): string;
43+
4244
/**
4345
* Sets the maximum number of messages to send per second (0 to disable).
4446
*/

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');

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');

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
4.4.0
55
-----
66

7+
* [BC BREAK] `TransportInterface` has a new `getName()` method
78
* [BC BREAK] Classes `AbstractApiTransport` and `AbstractHttpTransport` moved under `Transport` sub-namespace.
89
* [BC BREAK] Transports depend on `Symfony\Contracts\EventDispatcher\EventDispatcherInterface`
910
instead of `Symfony\Component\EventDispatcher\EventDispatcherInterface`.

FailoverTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ protected function getNextTransport(): ?TransportInterface
2828

2929
return $this->currentTransport;
3030
}
31+
32+
protected function getNameSymbol(): string
33+
{
34+
return '||';
35+
}
3136
}

FailoverTransportTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ public function testSendNoTransports()
2929
new FailoverTransport([]);
3030
}
3131

32+
public function testGetName()
33+
{
34+
$t1 = $this->createMock(TransportInterface::class);
35+
$t1->expects($this->once())->method('getName')->willReturn('t1://local');
36+
$t2 = $this->createMock(TransportInterface::class);
37+
$t2->expects($this->once())->method('getName')->willReturn('t2://local');
38+
$t = new FailoverTransport([$t1, $t2]);
39+
$this->assertEquals('t1://local || t2://local', $t->getName());
40+
}
41+
3242
public function testSendFirstWork()
3343
{
3444
$t1 = $this->createMock(TransportInterface::class);

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, [

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();

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));

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([

0 commit comments

Comments
 (0)