Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b24b507

Browse files
committed
[Mailer] add ability to set socket/http timeout via dsn
1 parent aa9ccf8 commit b24b507

17 files changed

+90
-35
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
6161
'Content-Type' => 'application/x-www-form-urlencoded',
6262
],
6363
'body' => $payload = $this->getPayload($email, $envelope),
64+
'timeout' => $this->timeout,
6465
]);
6566

6667
$result = new \SimpleXMLElement($response->getContent(false));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected function doSendHttp(SentMessage $message): ResponseInterface
6161
'Action' => 'SendRawEmail',
6262
'RawMessage.Data' => base64_encode($message->toString()),
6363
],
64+
'timeout' => $this->timeout,
6465
]);
6566

6667
$result = new \SimpleXMLElement($response->getContent(false));

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ public function create(Dsn $dsn): TransportInterface
3131
$port = $dsn->getPort();
3232

3333
if ('ses+api' === $scheme) {
34-
return (new SesApiTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
34+
$transport = (new SesApiTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
35+
} elseif ('ses+https' === $scheme || 'ses' === $scheme) {
36+
$transport = (new SesHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
37+
} elseif ('ses+smtp' === $scheme || 'ses+smtps' === $scheme) {
38+
$transport = new SesSmtpTransport($user, $password, $region, $this->dispatcher, $this->logger);
39+
} else {
40+
throw new UnsupportedSchemeException($dsn, 'ses', $this->getSupportedSchemes());
3541
}
3642

37-
if ('ses+https' === $scheme || 'ses' === $scheme) {
38-
return (new SesHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
43+
if ($timeout = $dsn->getOption('timeout')) {
44+
$transport->setTimeout($timeout);
3945
}
4046

41-
if ('ses+smtp' === $scheme || 'ses+smtps' === $scheme) {
42-
return new SesSmtpTransport($user, $password, $region, $this->dispatcher, $this->logger);
43-
}
44-
45-
throw new UnsupportedSchemeException($dsn, 'ses', $this->getSupportedSchemes());
47+
return $transport;
4648
}
4749

4850
protected function getSupportedSchemes(): array

src/Symfony/Component/Mailer/Bridge/Google/Transport/GmailTransportFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ final class GmailTransportFactory extends AbstractTransportFactory
2424
public function create(Dsn $dsn): TransportInterface
2525
{
2626
if (\in_array($dsn->getScheme(), $this->getSupportedSchemes())) {
27-
return new GmailSmtpTransport($this->getUser($dsn), $this->getPassword($dsn), $this->dispatcher, $this->logger);
27+
$transport = new GmailSmtpTransport($this->getUser($dsn), $this->getPassword($dsn), $this->dispatcher, $this->logger);
28+
29+
if ($timeout = $dsn->getOption('timeout')) {
30+
$transport->setTimeout($timeout);
31+
}
32+
33+
return $transport;
2834
}
2935

3036
throw new UnsupportedSchemeException($dsn, 'gmail', $this->getSupportedSchemes());

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
4646
{
4747
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/1.0/messages/send.json', [
4848
'json' => $this->getPayload($email, $envelope),
49+
'timeout' => $this->timeout,
4950
]);
5051

5152
$result = $response->toArray(false);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function doSendHttp(SentMessage $message): ResponseInterface
4949
'from_email' => $envelope->getSender()->toString(),
5050
'raw_message' => $message->toString(),
5151
],
52+
'timeout' => $this->timeout,
5253
]);
5354

5455
$result = $response->toArray(false);

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ public function create(Dsn $dsn): TransportInterface
2929
$port = $dsn->getPort();
3030

3131
if ('mandrill+api' === $scheme) {
32-
return (new MandrillApiTransport($user, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
33-
}
32+
$transport = (new MandrillApiTransport($user, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
33+
} elseif ('mandrill+https' === $scheme || 'mandrill' === $scheme) {
34+
$transport = (new MandrillHttpTransport($user, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
35+
} elseif ('mandrill+smtp' === $scheme || 'mandrill+smtps' === $scheme) {
36+
$password = $this->getPassword($dsn);
3437

35-
if ('mandrill+https' === $scheme || 'mandrill' === $scheme) {
36-
return (new MandrillHttpTransport($user, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
38+
$transport = new MandrillSmtpTransport($user, $password, $this->dispatcher, $this->logger);
39+
} else {
40+
throw new UnsupportedSchemeException($dsn, 'mandrill', $this->getSupportedSchemes());
3741
}
3842

39-
if ('mandrill+smtp' === $scheme || 'mandrill+smtps' === $scheme) {
40-
$password = $this->getPassword($dsn);
41-
42-
return new MandrillSmtpTransport($user, $password, $this->dispatcher, $this->logger);
43+
if ($timeout = $dsn->getOption('timeout')) {
44+
$transport->setTimeout($timeout);
4345
}
4446

45-
throw new UnsupportedSchemeException($dsn, 'mandrill', $this->getSupportedSchemes());
47+
return $transport;
4648
}
4749

4850
protected function getSupportedSchemes(): array

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
6060
'auth_basic' => 'api:'.$this->key,
6161
'headers' => $headers,
6262
'body' => $body->bodyToIterable(),
63+
'timeout' => $this->timeout,
6364
]);
6465

6566
$result = $response->toArray(false);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ protected function doSendHttp(SentMessage $message): ResponseInterface
6262
'auth_basic' => 'api:'.$this->key,
6363
'headers' => $headers,
6464
'body' => $body->bodyToIterable(),
65+
'timeout' => $this->timeout,
6566
]);
6667

6768
$result = $response->toArray(false);

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ public function create(Dsn $dsn): TransportInterface
3131
$port = $dsn->getPort();
3232

3333
if ('mailgun+api' === $scheme) {
34-
return (new MailgunApiTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
34+
$transport = (new MailgunApiTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
35+
} elseif ('mailgun+https' === $scheme || 'mailgun' === $scheme) {
36+
$transport = (new MailgunHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
37+
} elseif ('mailgun+smtp' === $scheme || 'mailgun+smtps' === $scheme) {
38+
$transport = new MailgunSmtpTransport($user, $password, $region, $this->dispatcher, $this->logger);
39+
} else {
40+
throw new UnsupportedSchemeException($dsn, 'mailgun', $this->getSupportedSchemes());
3541
}
3642

37-
if ('mailgun+https' === $scheme || 'mailgun' === $scheme) {
38-
return (new MailgunHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
43+
if ($timeout = $dsn->getOption('timeout')) {
44+
$transport->setTimeout($timeout);
3945
}
4046

41-
if ('mailgun+smtp' === $scheme || 'mailgun+smtps' === $scheme) {
42-
return new MailgunSmtpTransport($user, $password, $region, $this->dispatcher, $this->logger);
43-
}
44-
45-
throw new UnsupportedSchemeException($dsn, 'mailgun', $this->getSupportedSchemes());
47+
return $transport;
4648
}
4749

4850
protected function getSupportedSchemes(): array

0 commit comments

Comments
 (0)