[Mailer] Rename an exception class
This commit is contained in:
parent
74d5fa62ce
commit
2c58dcc34b
@ -120,7 +120,7 @@ class SesTransportFactoryTest extends TransportFactoryTestCase
|
||||
{
|
||||
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".',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ class GmailTransportFactoryTest extends TransportFactoryTestCase
|
||||
{
|
||||
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".',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ class MandrillTransportFactoryTest extends TransportFactoryTestCase
|
||||
{
|
||||
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".',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ class MailgunTransportFactoryTest extends TransportFactoryTestCase
|
||||
{
|
||||
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".',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ class PostmarkTransportFactoryTest extends TransportFactoryTestCase
|
||||
{
|
||||
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".',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ class SendgridTransportFactoryTest extends TransportFactoryTestCase
|
||||
{
|
||||
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".',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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 <molodchick@gmail.com>
|
||||
*/
|
||||
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()));
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Mailer\Exception;
|
||||
|
||||
use Symfony\Component\Mailer\Bridge;
|
||||
use Symfony\Component\Mailer\Transport\Dsn;
|
||||
|
||||
/**
|
||||
@ -18,8 +19,51 @@ use Symfony\Component\Mailer\Transport\Dsn;
|
||||
*/
|
||||
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.'.');
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class SendmailTransportFactoryTest extends TransportFactoryTestCase
|
||||
{
|
||||
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".',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory;
|
||||
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 @@ class Transport
|
||||
}
|
||||
}
|
||||
|
||||
throw new UnsupportedHostException($dsn);
|
||||
throw new UnsupportedSchemeException($dsn);
|
||||
}
|
||||
|
||||
private static function getDefaultFactories(EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null): iterable
|
||||
|
Reference in New Issue
Block a user