feature #39365 [Notifier] [DX] UnsupportedMessageTypeException for notifier transports (OskarStark)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[Notifier] [DX] UnsupportedMessageTypeException for notifier transports

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | --
| License       | MIT
| Doc PR        | --

I want to streamline the experience, creating new notifier transports. Maybe such exceptions fit well, as we are planing to get more and more transports and don't want to "pollute" the transports itself with repeatable code.

Please let me know if you are open to have such exceptions as I would like to introduce more of them for unsupported options for example and if this should be considered a new feature or it should be applied against `5.1`?

I am not sure about the signature and the name of the new `UnsupportedMessageTypeException`.

Cheers

Commits
-------

cf1d352eac [Notifier] [DX] UnsupportedMessageTypeException for notifier transports
This commit is contained in:
Jérémy Derussé 2020-12-11 21:40:04 +01:00
commit e5167e668c
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
48 changed files with 116 additions and 66 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Notifier\Bridge\Discord;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -57,7 +58,7 @@ final class DiscordTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
$messageOptions = $message->getOptions(); $messageOptions = $message->getOptions();

View File

@ -14,8 +14,8 @@ namespace Symfony\Component\Notifier\Bridge\Discord\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Discord\DiscordTransport; use Symfony\Component\Notifier\Bridge\Discord\DiscordTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -43,9 +43,10 @@ final class DiscordTransportTest extends TestCase
public function testSendNonChatMessageThrows() public function testSendNonChatMessageThrows()
{ {
$this->expectException(LogicException::class);
$transport = new DiscordTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class)); $transport = new DiscordTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
$this->expectException(UnsupportedMessageTypeException::class);
$transport->send($this->createMock(MessageInterface::class)); $transport->send($this->createMock(MessageInterface::class));
} }

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"require-dev": { "require-dev": {
"symfony/event-dispatcher": "^4.3|^5.0" "symfony/event-dispatcher": "^4.3|^5.0"

View File

@ -13,8 +13,8 @@ namespace Symfony\Component\Notifier\Bridge\Esendex;
use Symfony\Component\HttpClient\Exception\JsonException; use Symfony\Component\HttpClient\Exception\JsonException;
use Symfony\Component\HttpClient\Exception\TransportException as HttpClientTransportException; use Symfony\Component\HttpClient\Exception\TransportException as HttpClientTransportException;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -55,7 +55,7 @@ final class EsendexTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$messageData = [ $messageData = [

View File

@ -14,8 +14,8 @@ namespace Symfony\Component\Notifier\Bridge\Esendex\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransport; use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -43,7 +43,8 @@ final class EsendexTransportTest extends TestCase
{ {
$transport = new EsendexTransport('testToken', 'accountReference', 'from', $this->createMock(HttpClientInterface::class)); $transport = new EsendexTransport('testToken', 'accountReference', 'from', $this->createMock(HttpClientInterface::class));
$this->expectException(LogicException::class); $this->expectException(UnsupportedMessageTypeException::class);
$transport->send($this->createMock(MessageInterface::class)); $transport->send($this->createMock(MessageInterface::class));
} }

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.4|^5.0", "symfony/http-client": "^4.4|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Esendex\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Esendex\\": "" },

View File

@ -12,8 +12,8 @@
namespace Symfony\Component\Notifier\Bridge\Firebase; namespace Symfony\Component\Notifier\Bridge\Firebase;
use Symfony\Component\Notifier\Exception\InvalidArgumentException; use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -54,7 +54,7 @@ final class FirebaseTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
$endpoint = sprintf('https://%s', $this->getEndpoint()); $endpoint = sprintf('https://%s', $this->getEndpoint());

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Firebase\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Firebase\\": "" },

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\FreeMobile; namespace Symfony\Component\Notifier\Bridge\FreeMobile;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -55,7 +55,7 @@ final class FreeMobileTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$this->supports($message)) { if (!$this->supports($message)) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given) and configured with your phone number.', __CLASS__, SmsMessage::class, \get_class($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$response = $this->client->request('POST', $this->getEndpoint(), [ $response = $this->client->request('POST', $this->getEndpoint(), [

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Notifier\Bridge\FreeMobile\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransport; use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransport;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -46,7 +46,7 @@ final class FreeMobileTransportTest extends TestCase
{ {
$transport = $this->getTransport('0611223344'); $transport = $this->getTransport('0611223344');
$this->expectException(LogicException::class); $this->expectException(UnsupportedMessageTypeException::class);
$transport->send($this->createMock(MessageInterface::class)); $transport->send($this->createMock(MessageInterface::class));
} }
@ -55,7 +55,7 @@ final class FreeMobileTransportTest extends TestCase
{ {
$transport = $this->getTransport('0611223344'); $transport = $this->getTransport('0611223344');
$this->expectException(LogicException::class); $this->expectException(UnsupportedMessageTypeException::class);
$transport->send(new SmsMessage('0699887766', 'Hello!')); $transport->send(new SmsMessage('0699887766', 'Hello!'));
} }

View File

@ -19,7 +19,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.1", "symfony/http-client": "^4.3|^5.1",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" },

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Notifier\Bridge\GoogleChat;
use Symfony\Component\HttpClient\Exception\JsonException; use Symfony\Component\HttpClient\Exception\JsonException;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -87,7 +88,7 @@ final class GoogleChatTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, \get_class($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
if ($message->getOptions() && !$message->getOptions() instanceof GoogleChatOptions) { if ($message->getOptions() && !$message->getOptions() instanceof GoogleChatOptions) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, GoogleChatOptions::class)); throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, GoogleChatOptions::class));

View File

@ -17,6 +17,7 @@ use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransport; use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransport;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\MessageOptionsInterface; use Symfony\Component\Notifier\Message\MessageOptionsInterface;
@ -44,10 +45,10 @@ class GoogleChatTransportTest extends TestCase
public function testSendNonChatMessageThrows(): void public function testSendNonChatMessageThrows(): void
{ {
$this->expectException(LogicException::class);
$transport = new GoogleChatTransport('My-Space', 'theAccessKey', 'theAccessToken=', $this->createMock(HttpClientInterface::class)); $transport = new GoogleChatTransport('My-Space', 'theAccessKey', 'theAccessToken=', $this->createMock(HttpClientInterface::class));
$this->expectException(UnsupportedMessageTypeException::class);
$transport->send($this->createMock(MessageInterface::class)); $transport->send($this->createMock(MessageInterface::class));
} }

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\GoogleChat\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\GoogleChat\\": "" },

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\Infobip; namespace Symfony\Component\Notifier\Bridge\Infobip;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -52,7 +52,7 @@ final class InfobipTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$endpoint = sprintf('https://%s/sms/2/text/advanced', $this->getEndpoint()); $endpoint = sprintf('https://%s/sms/2/text/advanced', $this->getEndpoint());

View File

@ -22,7 +22,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Infobip\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Infobip\\": "" },

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Notifier\Bridge\LinkedIn;
use Symfony\Component\Notifier\Bridge\LinkedIn\Share\AuthorShare; use Symfony\Component\Notifier\Bridge\LinkedIn\Share\AuthorShare;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -61,7 +62,7 @@ final class LinkedInTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, \get_class($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
if ($message->getOptions() && !$message->getOptions() instanceof LinkedInOptions) { if ($message->getOptions() && !$message->getOptions() instanceof LinkedInOptions) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, LinkedInOptions::class)); throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, LinkedInOptions::class));

View File

@ -7,6 +7,7 @@ use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransport; use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransport;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\MessageOptionsInterface; use Symfony\Component\Notifier\Message\MessageOptionsInterface;
@ -31,10 +32,10 @@ final class LinkedInTransportTest extends TestCase
public function testSendNonChatMessageThrows(): void public function testSendNonChatMessageThrows(): void
{ {
$this->expectException(LogicException::class);
$transport = $this->getTransport(); $transport = $this->getTransport();
$this->expectException(UnsupportedMessageTypeException::class);
$transport->send($this->createMock(MessageInterface::class)); $transport->send($this->createMock(MessageInterface::class));
} }

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LinkedIn\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LinkedIn\\": "" },

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\Mattermost; namespace Symfony\Component\Notifier\Bridge\Mattermost;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -54,7 +54,7 @@ final class MattermostTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
$endpoint = sprintf('https://%s/api/v4/posts', $this->getEndpoint()); $endpoint = sprintf('https://%s/api/v4/posts', $this->getEndpoint());

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mattermost\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mattermost\\": "" },

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Notifier\Bridge\Mobyt;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -57,7 +58,7 @@ final class MobytTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, \get_class($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
if ($message->getOptions() && !$message->getOptions() instanceof MobytOptions) { if ($message->getOptions() && !$message->getOptions() instanceof MobytOptions) {

View File

@ -19,7 +19,7 @@
"ext-json": "*", "ext-json": "*",
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mobyt\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mobyt\\": "" },

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\Nexmo; namespace Symfony\Component\Notifier\Bridge\Nexmo;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -55,7 +55,7 @@ final class NexmoTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/sms/json', [ $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/sms/json', [

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Nexmo\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Nexmo\\": "" },

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\OvhCloud; namespace Symfony\Component\Notifier\Bridge\OvhCloud;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -57,7 +57,7 @@ final class OvhCloudTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$endpoint = sprintf('https://%s/1.0/sms/%s/jobs', $this->getEndpoint(), $this->serviceName); $endpoint = sprintf('https://%s/1.0/sms/%s/jobs', $this->getEndpoint(), $this->serviceName);

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Notifier\Bridge\RocketChat;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -57,7 +58,7 @@ final class RocketChatTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
if ($message->getOptions() && !$message->getOptions() instanceof RocketChatOptions) { if ($message->getOptions() && !$message->getOptions() instanceof RocketChatOptions) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, RocketChatOptions::class)); throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, RocketChatOptions::class));

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\RocketChat\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\RocketChat\\": "" },

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\Sendinblue; namespace Symfony\Component\Notifier\Bridge\Sendinblue;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -53,7 +53,7 @@ final class SendinblueTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [ $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [

View File

@ -14,8 +14,8 @@ namespace Symfony\Component\Notifier\Bridge\Sendinblue\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Sendinblue\SendinblueTransport; use Symfony\Component\Notifier\Bridge\Sendinblue\SendinblueTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -42,7 +42,8 @@ final class SendinblueTransportTest extends TestCase
{ {
$transport = $this->initTransport(); $transport = $this->initTransport();
$this->expectException(LogicException::class); $this->expectException(UnsupportedMessageTypeException::class);
$transport->send($this->createMock(MessageInterface::class)); $transport->send($this->createMock(MessageInterface::class));
} }

View File

@ -19,7 +19,7 @@
"ext-json": "*", "ext-json": "*",
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sendinblue\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sendinblue\\": "" },

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\Sinch; namespace Symfony\Component\Notifier\Bridge\Sinch;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -55,7 +55,7 @@ final class SinchTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$endpoint = sprintf('https://%s/xms/v1/%s/batches', $this->getEndpoint(), $this->accountSid); $endpoint = sprintf('https://%s/xms/v1/%s/batches', $this->getEndpoint(), $this->accountSid);

View File

@ -19,7 +19,7 @@
"php": ">=7.2.5", "php": ">=7.2.5",
"ext-json": "*", "ext-json": "*",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" },

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Notifier\Bridge\Slack;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -57,7 +58,7 @@ final class SlackTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
if ($message->getOptions() && !$message->getOptions() instanceof SlackOptions) { if ($message->getOptions() && !$message->getOptions() instanceof SlackOptions) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, SlackOptions::class)); throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, SlackOptions::class));

View File

@ -17,6 +17,7 @@ use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\Bridge\Slack\SlackTransport; use Symfony\Component\Notifier\Bridge\Slack\SlackTransport;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\MessageOptionsInterface; use Symfony\Component\Notifier\Message\MessageOptionsInterface;
@ -47,10 +48,10 @@ final class SlackTransportTest extends TestCase
public function testSendNonChatMessageThrows(): void public function testSendNonChatMessageThrows(): void
{ {
$this->expectException(LogicException::class);
$transport = new SlackTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class)); $transport = new SlackTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
$this->expectException(UnsupportedMessageTypeException::class);
$transport->send($this->createMock(MessageInterface::class)); $transport->send($this->createMock(MessageInterface::class));
} }

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"require-dev": { "require-dev": {
"symfony/event-dispatcher": "^4.3|^5.0" "symfony/event-dispatcher": "^4.3|^5.0"

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\Smsapi; namespace Symfony\Component\Notifier\Bridge\Smsapi;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -52,7 +52,7 @@ final class SmsapiTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$endpoint = sprintf('https://%s/sms.do', $this->getEndpoint()); $endpoint = sprintf('https://%s/sms.do', $this->getEndpoint());

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsapi\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsapi\\": "" },

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Notifier\Bridge\Telegram;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -62,7 +63,7 @@ final class TelegramTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
if ($message->getOptions() && !$message->getOptions() instanceof TelegramOptions) { if ($message->getOptions() && !$message->getOptions() instanceof TelegramOptions) {

View File

@ -15,8 +15,8 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions; use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport; use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -44,9 +44,10 @@ final class TelegramTransportTest extends TestCase
public function testSendNonChatMessageThrows(): void public function testSendNonChatMessageThrows(): void
{ {
$this->expectException(LogicException::class);
$transport = new TelegramTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class)); $transport = new TelegramTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
$this->expectException(UnsupportedMessageTypeException::class);
$transport->send($this->createMock(MessageInterface::class)); $transport->send($this->createMock(MessageInterface::class));
} }

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"require-dev": { "require-dev": {
"symfony/event-dispatcher": "^4.3|^5.0" "symfony/event-dispatcher": "^4.3|^5.0"

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Notifier\Bridge\Twilio; namespace Symfony\Component\Notifier\Bridge\Twilio;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
@ -55,7 +55,7 @@ final class TwilioTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof SmsMessage) { if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
} }
$endpoint = sprintf('https://%s/2010-04-01/Accounts/%s/Messages.json', $this->getEndpoint(), $this->accountSid); $endpoint = sprintf('https://%s/2010-04-01/Accounts/%s/Messages.json', $this->getEndpoint(), $this->accountSid);

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Twilio\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Twilio\\": "" },

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Notifier\Bridge\Zulip;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;
@ -56,7 +57,7 @@ class ZulipTransport extends AbstractTransport
protected function doSend(MessageInterface $message): SentMessage protected function doSend(MessageInterface $message): SentMessage
{ {
if (!$message instanceof ChatMessage) { if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message))); throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class, $message);
} }
if (null !== $message->getOptions() && !($message->getOptions() instanceof ZulipOptions)) { if (null !== $message->getOptions() && !($message->getOptions() instanceof ZulipOptions)) {

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0", "symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.2" "symfony/notifier": "^5.3"
}, },
"autoload": { "autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Zulip\\": "" }, "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Zulip\\": "" },

View File

@ -0,0 +1,34 @@
<?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\Notifier\Exception;
use Symfony\Component\Notifier\Message\MessageInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*
* @experimental in 5.3
*/
class UnsupportedMessageTypeException extends LogicException
{
public function __construct(string $transport, string $supported, MessageInterface $given)
{
$message = sprintf(
'The "%s" transport only supports instances of "%s" (instance of "%s" given).',
$transport,
$supported,
get_debug_type($given)
);
parent::__construct($message);
}
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Notifier\Transport; namespace Symfony\Component\Notifier\Transport;
use Symfony\Component\Notifier\Exception\TransportExceptionInterface; use Symfony\Component\Notifier\Exception\TransportExceptionInterface;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Message\SentMessage;