UnsupportedSchemeException.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Notifier\Exception;
  11. use Symfony\Component\Notifier\Bridge;
  12. use Symfony\Component\Notifier\Transport\Dsn;
  13. /**
  14. * @author Konstantin Myakshin <molodchick@gmail.com>
  15. *
  16. * @experimental in 5.1
  17. */
  18. class UnsupportedSchemeException extends LogicException
  19. {
  20. private const SCHEME_TO_PACKAGE_MAP = [
  21. 'slack' => [
  22. 'class' => Bridge\Slack\SlackTransportFactory::class,
  23. 'package' => 'symfony/slack-notifier',
  24. ],
  25. 'telegram' => [
  26. 'class' => Bridge\Telegram\TelegramTransportFactory::class,
  27. 'package' => 'symfony/telegram-notifier',
  28. ],
  29. 'mattermost' => [
  30. 'class' => Bridge\Mattermost\MattermostTransportFactory::class,
  31. 'package' => 'symfony/mattermost-notifier',
  32. ],
  33. 'nexmo' => [
  34. 'class' => Bridge\Nexmo\NexmoTransportFactory::class,
  35. 'package' => 'symfony/nexmo-notifier',
  36. ],
  37. 'rocketchat' => [
  38. 'class' => Bridge\RocketChat\RocketChatTransportFactory::class,
  39. 'package' => 'rocketchat-notifier',
  40. ],
  41. 'twilio' => [
  42. 'class' => Bridge\Twilio\TwilioTransportFactory::class,
  43. 'package' => 'symfony/twilio-notifier',
  44. ],
  45. 'firebase' => [
  46. 'class' => Bridge\Firebase\FirebaseTransportFactory::class,
  47. 'package' => 'symfony/firebase-notifier',
  48. ],
  49. 'free-mobile' => [
  50. 'class' => Bridge\FreeMobile\FreeMobileTransportFactory::class,
  51. 'package' => 'symfony/free-mobile-notifier',
  52. ],
  53. 'ovhcloud' => [
  54. 'class' => Bridge\OvhCloud\OvhCloudTransportFactory::class,
  55. 'package' => 'symfony/ovhcloud-notifier',
  56. ],
  57. 'sinch' => [
  58. 'class' => Bridge\Sinch\SinchTransportFactory::class,
  59. 'package' => 'symfony/sinch-notifier',
  60. ],
  61. ];
  62. /**
  63. * @param string[] $supported
  64. */
  65. public function __construct(Dsn $dsn, string $name = null, array $supported = [])
  66. {
  67. $provider = $dsn->getScheme();
  68. if (false !== $pos = strpos($provider, '+')) {
  69. $provider = substr($provider, 0, $pos);
  70. }
  71. $package = self::SCHEME_TO_PACKAGE_MAP[$provider] ?? null;
  72. if ($package && !class_exists($package['class'])) {
  73. parent::__construct(sprintf('Unable to send notification via "%s" as the bridge is not installed; try running "composer require %s".', $provider, $package['package']));
  74. return;
  75. }
  76. $message = sprintf('The "%s" scheme is not supported', $dsn->getScheme());
  77. if ($name && $supported) {
  78. $message .= sprintf('; supported schemes for notifier "%s" are: "%s"', $name, implode('", "', $supported));
  79. }
  80. parent::__construct($message.'.');
  81. }
  82. }