diff --git a/src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesTransportFactoryTest.php b/src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesTransportFactoryTest.php index 7fada879ddc69..c5d61db11d5fe 100644 --- a/src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesTransportFactoryTest.php @@ -120,7 +120,7 @@ public function unsupportedSchemeProvider(): iterable { yield [ new Dsn('ses+foo', 'default', self::USER, self::PASSWORD), - 'The "ses+foo" scheme is not supported. Supported schemes for mailer "ses" are: "ses", "ses+api", "ses+https", "ses+smtp", "ses+smtps".', + 'The "ses+foo" scheme is not supported; supported schemes for mailer "ses" are: "ses", "ses+api", "ses+https", "ses+smtp", "ses+smtps".', ]; } diff --git a/src/Symfony/Component/Mailer/Bridge/Google/Tests/Transport/GmailTransportFactoryTest.php b/src/Symfony/Component/Mailer/Bridge/Google/Tests/Transport/GmailTransportFactoryTest.php index 456be78483066..ff9e41058434f 100644 --- a/src/Symfony/Component/Mailer/Bridge/Google/Tests/Transport/GmailTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Google/Tests/Transport/GmailTransportFactoryTest.php @@ -60,7 +60,7 @@ public function unsupportedSchemeProvider(): iterable { yield [ new Dsn('gmail+foo', 'default', self::USER, self::PASSWORD), - 'The "gmail+foo" scheme is not supported. Supported schemes for mailer "gmail" are: "gmail", "gmail+smtp", "gmail+smtps".', + 'The "gmail+foo" scheme is not supported; supported schemes for mailer "gmail" are: "gmail", "gmail+smtp", "gmail+smtps".', ]; } diff --git a/src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillTransportFactoryTest.php b/src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillTransportFactoryTest.php index 317cbb35cdcf7..c905266756d52 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillTransportFactoryTest.php @@ -105,7 +105,7 @@ public function unsupportedSchemeProvider(): iterable { yield [ new Dsn('mandrill+foo', 'default', self::USER), - 'The "mandrill+foo" scheme is not supported. Supported schemes for mailer "mandrill" are: "mandrill", "mandrill+api", "mandrill+https", "mandrill+smtp", "mandrill+smtps".', + 'The "mandrill+foo" scheme is not supported; supported schemes for mailer "mandrill" are: "mandrill", "mandrill+api", "mandrill+https", "mandrill+smtp", "mandrill+smtps".', ]; } diff --git a/src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunTransportFactoryTest.php b/src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunTransportFactoryTest.php index 67a3ed51c4291..118964995028a 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunTransportFactoryTest.php @@ -110,7 +110,7 @@ public function unsupportedSchemeProvider(): iterable { yield [ new Dsn('mailgun+foo', 'default', self::USER, self::PASSWORD), - 'The "mailgun+foo" scheme is not supported. Supported schemes for mailer "mailgun" are: "mailgun", "mailgun+api", "mailgun+https", "mailgun+smtp", "mailgun+smtps".', + 'The "mailgun+foo" scheme is not supported; supported schemes for mailer "mailgun" are: "mailgun", "mailgun+api", "mailgun+https", "mailgun+smtp", "mailgun+smtps".', ]; } diff --git a/src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkTransportFactoryTest.php b/src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkTransportFactoryTest.php index d93a1a2081bb1..2959cd3a4188f 100644 --- a/src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkTransportFactoryTest.php @@ -88,7 +88,7 @@ public function unsupportedSchemeProvider(): iterable { yield [ new Dsn('postmark+foo', 'default', self::USER), - 'The "postmark+foo" scheme is not supported. Supported schemes for mailer "postmark" are: "postmark", "postmark+api", "postmark+smtp", "postmark+smtps".', + 'The "postmark+foo" scheme is not supported; supported schemes for mailer "postmark" are: "postmark", "postmark+api", "postmark+smtp", "postmark+smtps".', ]; } diff --git a/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridTransportFactoryTest.php b/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridTransportFactoryTest.php index b32c37e0c8b48..cb4f775e2a5b4 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridTransportFactoryTest.php @@ -88,7 +88,7 @@ public function unsupportedSchemeProvider(): iterable { yield [ new Dsn('sendgrid+foo', 'sendgrid', self::USER), - 'The "sendgrid+foo" scheme is not supported. Supported schemes for mailer "sendgrid" are: "sendgrid", "sendgrid+api", "sendgrid+smtp", "sendgrid+smtps".', + 'The "sendgrid+foo" scheme is not supported; supported schemes for mailer "sendgrid" are: "sendgrid", "sendgrid+api", "sendgrid+smtp", "sendgrid+smtps".', ]; } diff --git a/src/Symfony/Component/Mailer/Exception/UnsupportedHostException.php b/src/Symfony/Component/Mailer/Exception/UnsupportedHostException.php deleted file mode 100644 index 94feb66267d5d..0000000000000 --- a/src/Symfony/Component/Mailer/Exception/UnsupportedHostException.php +++ /dev/null @@ -1,64 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Mailer\Exception; - -use Symfony\Component\Mailer\Bridge; -use Symfony\Component\Mailer\Transport\Dsn; - -/** - * @author Konstantin Myakshin - */ -class UnsupportedHostException extends LogicException -{ - private const HOST_TO_PACKAGE_MAP = [ - 'gmail' => [ - 'class' => Bridge\Google\Transport\GmailTransportFactory::class, - 'package' => 'symfony/google-mailer', - ], - 'mailgun' => [ - 'class' => Bridge\Mailgun\Transport\MailgunTransportFactory::class, - 'package' => 'symfony/mailgun-mailer', - ], - 'postmark' => [ - 'class' => Bridge\Postmark\Transport\PostmarkTransportFactory::class, - 'package' => 'symfony/postmark-mailer', - ], - 'sendgrid' => [ - 'class' => Bridge\Sendgrid\Transport\SendgridTransportFactory::class, - 'package' => 'symfony/sendgrid-mailer', - ], - 'ses' => [ - 'class' => Bridge\Amazon\Transport\SesTransportFactory::class, - 'package' => 'symfony/amazon-mailer', - ], - 'mandrill' => [ - 'class' => Bridge\Mailchimp\Transport\MandrillTransportFactory::class, - 'package' => 'symfony/mailchimp-mailer', - ], - ]; - - public function __construct(Dsn $dsn) - { - $provider = $dsn->getScheme(); - if (false !== $pos = strpos($provider, '+')) { - $provider = substr($provider, 0, $pos); - } - $package = self::HOST_TO_PACKAGE_MAP[$provider] ?? null; - if ($package && !class_exists($package['class'])) { - parent::__construct(sprintf('Unable to send emails via "%s" as the bridge is not installed. Try running "composer require %s".', $provider, $package['package'])); - - return; - } - - parent::__construct(sprintf('The "%s" scheme is not supported.', $dsn->getScheme())); - } -} diff --git a/src/Symfony/Component/Mailer/Exception/UnsupportedSchemeException.php b/src/Symfony/Component/Mailer/Exception/UnsupportedSchemeException.php index 165d644cb301e..dc367df85aa6d 100644 --- a/src/Symfony/Component/Mailer/Exception/UnsupportedSchemeException.php +++ b/src/Symfony/Component/Mailer/Exception/UnsupportedSchemeException.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Mailer\Exception; +use Symfony\Component\Mailer\Bridge; use Symfony\Component\Mailer\Transport\Dsn; /** @@ -18,8 +19,51 @@ */ class UnsupportedSchemeException extends LogicException { - public function __construct(Dsn $dsn, string $name, array $supported) + private const SCHEME_TO_PACKAGE_MAP = [ + 'gmail' => [ + 'class' => Bridge\Google\Transport\GmailTransportFactory::class, + 'package' => 'symfony/google-mailer', + ], + 'mailgun' => [ + 'class' => Bridge\Mailgun\Transport\MailgunTransportFactory::class, + 'package' => 'symfony/mailgun-mailer', + ], + 'postmark' => [ + 'class' => Bridge\Postmark\Transport\PostmarkTransportFactory::class, + 'package' => 'symfony/postmark-mailer', + ], + 'sendgrid' => [ + 'class' => Bridge\Sendgrid\Transport\SendgridTransportFactory::class, + 'package' => 'symfony/sendgrid-mailer', + ], + 'ses' => [ + 'class' => Bridge\Amazon\Transport\SesTransportFactory::class, + 'package' => 'symfony/amazon-mailer', + ], + 'mandrill' => [ + 'class' => Bridge\Mailchimp\Transport\MandrillTransportFactory::class, + 'package' => 'symfony/mailchimp-mailer', + ], + ]; + + public function __construct(Dsn $dsn, string $name = null, array $supported = []) { - parent::__construct(sprintf('The "%s" scheme is not supported. Supported schemes for mailer "%s" are: "%s".', $dsn->getScheme(), $name, implode('", "', $supported))); + $provider = $dsn->getScheme(); + if (false !== $pos = strpos($provider, '+')) { + $provider = substr($provider, 0, $pos); + } + $package = self::SCHEME_TO_PACKAGE_MAP[$provider] ?? null; + if ($package && !class_exists($package['class'])) { + parent::__construct(sprintf('Unable to send emails via "%s" as the bridge is not installed; try running "composer require %s".', $provider, $package['package'])); + + return; + } + + $message = sprintf('The "%s" scheme is not supported', $dsn->getScheme()); + if ($name && $supported) { + $message .= sprintf('; supported schemes for mailer "%s" are: "%s"', $name, implode('", "', $supported)); + } + + parent::__construct($message.'.'); } } diff --git a/src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php b/src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php index 078b00b6f5b54..1898e143d5d0e 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php @@ -44,7 +44,7 @@ public function unsupportedSchemeProvider(): iterable { yield [ new Dsn('sendmail+http', 'default'), - 'The "sendmail+http" scheme is not supported. Supported schemes for mailer "sendmail" are: "sendmail", "sendmail+smtp".', + 'The "sendmail+http" scheme is not supported; supported schemes for mailer "sendmail" are: "sendmail", "sendmail+smtp".', ]; } } diff --git a/src/Symfony/Component/Mailer/Transport.php b/src/Symfony/Component/Mailer/Transport.php index d3c4e58f6a3ff..45dfc8b9ba2e7 100644 --- a/src/Symfony/Component/Mailer/Transport.php +++ b/src/Symfony/Component/Mailer/Transport.php @@ -19,7 +19,7 @@ use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory; use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory; use Symfony\Component\Mailer\Exception\InvalidArgumentException; -use Symfony\Component\Mailer\Exception\UnsupportedHostException; +use Symfony\Component\Mailer\Exception\UnsupportedSchemeException; use Symfony\Component\Mailer\Transport\Dsn; use Symfony\Component\Mailer\Transport\FailoverTransport; use Symfony\Component\Mailer\Transport\NullTransportFactory; @@ -146,7 +146,7 @@ public function fromDsnObject(Dsn $dsn): TransportInterface } } - throw new UnsupportedHostException($dsn); + throw new UnsupportedSchemeException($dsn); } private static function getDefaultFactories(EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null): iterable