Skip to content

Commit 7d7364a

Browse files
committed
Merge branch '4.4'
* 4.4: [Mailer] Rename an exception class [Workflow] Use a better exception message when many workflow are found use debug.file_link_formatter service when possible
2 parents f16f58e + 47e4615 commit 7d7364a

File tree

4 files changed

+49
-69
lines changed

4 files changed

+49
-69
lines changed

Exception/UnsupportedHostException.php

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

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 <molodchick@gmail.com>
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
}

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
}

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)