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

Skip to content

Commit 6e7182f

Browse files
committed
feature #33565 [Mailer] Rename an exception class (fabpot)
This PR was merged into the 4.4 branch. Discussion ---------- [Mailer] Rename an exception class | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT | Doc PR | n/a <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> Commits ------- 2c58dcc [Mailer] Rename an exception class
2 parents 74d5fa6 + 2c58dcc commit 6e7182f

File tree

10 files changed

+55
-75
lines changed

10 files changed

+55
-75
lines changed

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesTransportFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function unsupportedSchemeProvider(): iterable
120120
{
121121
yield [
122122
new Dsn('ses+foo', 'default', self::USER, self::PASSWORD),
123-
'The "ses+foo" scheme is not supported. Supported schemes for mailer "ses" are: "ses", "ses+api", "ses+https", "ses+smtp", "ses+smtps".',
123+
'The "ses+foo" scheme is not supported; supported schemes for mailer "ses" are: "ses", "ses+api", "ses+https", "ses+smtp", "ses+smtps".',
124124
];
125125
}
126126

src/Symfony/Component/Mailer/Bridge/Google/Tests/Transport/GmailTransportFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function unsupportedSchemeProvider(): iterable
6060
{
6161
yield [
6262
new Dsn('gmail+foo', 'default', self::USER, self::PASSWORD),
63-
'The "gmail+foo" scheme is not supported. Supported schemes for mailer "gmail" are: "gmail", "gmail+smtp", "gmail+smtps".',
63+
'The "gmail+foo" scheme is not supported; supported schemes for mailer "gmail" are: "gmail", "gmail+smtp", "gmail+smtps".',
6464
];
6565
}
6666

src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillTransportFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function unsupportedSchemeProvider(): iterable
105105
{
106106
yield [
107107
new Dsn('mandrill+foo', 'default', self::USER),
108-
'The "mandrill+foo" scheme is not supported. Supported schemes for mailer "mandrill" are: "mandrill", "mandrill+api", "mandrill+https", "mandrill+smtp", "mandrill+smtps".',
108+
'The "mandrill+foo" scheme is not supported; supported schemes for mailer "mandrill" are: "mandrill", "mandrill+api", "mandrill+https", "mandrill+smtp", "mandrill+smtps".',
109109
];
110110
}
111111

src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunTransportFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function unsupportedSchemeProvider(): iterable
110110
{
111111
yield [
112112
new Dsn('mailgun+foo', 'default', self::USER, self::PASSWORD),
113-
'The "mailgun+foo" scheme is not supported. Supported schemes for mailer "mailgun" are: "mailgun", "mailgun+api", "mailgun+https", "mailgun+smtp", "mailgun+smtps".',
113+
'The "mailgun+foo" scheme is not supported; supported schemes for mailer "mailgun" are: "mailgun", "mailgun+api", "mailgun+https", "mailgun+smtp", "mailgun+smtps".',
114114
];
115115
}
116116

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkTransportFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function unsupportedSchemeProvider(): iterable
8888
{
8989
yield [
9090
new Dsn('postmark+foo', 'default', self::USER),
91-
'The "postmark+foo" scheme is not supported. Supported schemes for mailer "postmark" are: "postmark", "postmark+api", "postmark+smtp", "postmark+smtps".',
91+
'The "postmark+foo" scheme is not supported; supported schemes for mailer "postmark" are: "postmark", "postmark+api", "postmark+smtp", "postmark+smtps".',
9292
];
9393
}
9494

src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridTransportFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function unsupportedSchemeProvider(): iterable
8888
{
8989
yield [
9090
new Dsn('sendgrid+foo', 'sendgrid', self::USER),
91-
'The "sendgrid+foo" scheme is not supported. Supported schemes for mailer "sendgrid" are: "sendgrid", "sendgrid+api", "sendgrid+smtp", "sendgrid+smtps".',
91+
'The "sendgrid+foo" scheme is not supported; supported schemes for mailer "sendgrid" are: "sendgrid", "sendgrid+api", "sendgrid+smtp", "sendgrid+smtps".',
9292
];
9393
}
9494

src/Symfony/Component/Mailer/Exception/UnsupportedHostException.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/Symfony/Component/Mailer/Exception/UnsupportedSchemeException.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,59 @@
1111

1212
namespace Symfony\Component\Mailer\Exception;
1313

14+
use Symfony\Component\Mailer\Bridge;
1415
use Symfony\Component\Mailer\Transport\Dsn;
1516

1617
/**
1718
* @author Konstantin Myakshin <[email protected]>
1819
*/
1920
class UnsupportedSchemeException extends LogicException
2021
{
21-
public function __construct(Dsn $dsn, string $name, array $supported)
22+
private const SCHEME_TO_PACKAGE_MAP = [
23+
'gmail' => [
24+
'class' => Bridge\Google\Transport\GmailTransportFactory::class,
25+
'package' => 'symfony/google-mailer',
26+
],
27+
'mailgun' => [
28+
'class' => Bridge\Mailgun\Transport\MailgunTransportFactory::class,
29+
'package' => 'symfony/mailgun-mailer',
30+
],
31+
'postmark' => [
32+
'class' => Bridge\Postmark\Transport\PostmarkTransportFactory::class,
33+
'package' => 'symfony/postmark-mailer',
34+
],
35+
'sendgrid' => [
36+
'class' => Bridge\Sendgrid\Transport\SendgridTransportFactory::class,
37+
'package' => 'symfony/sendgrid-mailer',
38+
],
39+
'ses' => [
40+
'class' => Bridge\Amazon\Transport\SesTransportFactory::class,
41+
'package' => 'symfony/amazon-mailer',
42+
],
43+
'mandrill' => [
44+
'class' => Bridge\Mailchimp\Transport\MandrillTransportFactory::class,
45+
'package' => 'symfony/mailchimp-mailer',
46+
],
47+
];
48+
49+
public function __construct(Dsn $dsn, string $name = null, array $supported = [])
2250
{
23-
parent::__construct(sprintf('The "%s" scheme is not supported. Supported schemes for mailer "%s" are: "%s".', $dsn->getScheme(), $name, implode('", "', $supported)));
51+
$provider = $dsn->getScheme();
52+
if (false !== $pos = strpos($provider, '+')) {
53+
$provider = substr($provider, 0, $pos);
54+
}
55+
$package = self::SCHEME_TO_PACKAGE_MAP[$provider] ?? null;
56+
if ($package && !class_exists($package['class'])) {
57+
parent::__construct(sprintf('Unable to send emails via "%s" as the bridge is not installed; try running "composer require %s".', $provider, $package['package']));
58+
59+
return;
60+
}
61+
62+
$message = sprintf('The "%s" scheme is not supported', $dsn->getScheme());
63+
if ($name && $supported) {
64+
$message .= sprintf('; supported schemes for mailer "%s" are: "%s"', $name, implode('", "', $supported));
65+
}
66+
67+
parent::__construct($message.'.');
2468
}
2569
}

src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function unsupportedSchemeProvider(): iterable
4444
{
4545
yield [
4646
new Dsn('sendmail+http', 'default'),
47-
'The "sendmail+http" scheme is not supported. Supported schemes for mailer "sendmail" are: "sendmail", "sendmail+smtp".',
47+
'The "sendmail+http" scheme is not supported; supported schemes for mailer "sendmail" are: "sendmail", "sendmail+smtp".',
4848
];
4949
}
5050
}

src/Symfony/Component/Mailer/Transport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
2020
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory;
2121
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
22-
use Symfony\Component\Mailer\Exception\UnsupportedHostException;
22+
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
2323
use Symfony\Component\Mailer\Transport\Dsn;
2424
use Symfony\Component\Mailer\Transport\FailoverTransport;
2525
use Symfony\Component\Mailer\Transport\NullTransportFactory;
@@ -146,7 +146,7 @@ public function fromDsnObject(Dsn $dsn): TransportInterface
146146
}
147147
}
148148

149-
throw new UnsupportedHostException($dsn);
149+
throw new UnsupportedSchemeException($dsn);
150150
}
151151

152152
private static function getDefaultFactories(EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null): iterable

0 commit comments

Comments
 (0)