vendor/symfony/messenger/Transport/TransportFactory.php line 32

Open in your IDE?
  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\Messenger\Transport;
  11. use Symfony\Component\Messenger\Exception\InvalidArgumentException;
  12. use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
  13. /**
  14.  * @author Samuel Roze <samuel.roze@gmail.com>
  15.  */
  16. class TransportFactory implements TransportFactoryInterface
  17. {
  18.     private $factories;
  19.     /**
  20.      * @param iterable<mixed, TransportFactoryInterface> $factories
  21.      */
  22.     public function __construct(iterable $factories)
  23.     {
  24.         $this->factories $factories;
  25.     }
  26.     public function createTransport(string $dsn, array $optionsSerializerInterface $serializer): TransportInterface
  27.     {
  28.         foreach ($this->factories as $factory) {
  29.             if ($factory->supports($dsn$options)) {
  30.                 return $factory->createTransport($dsn$options$serializer);
  31.             }
  32.         }
  33.         // Help the user to select Symfony packages based on protocol.
  34.         $packageSuggestion '';
  35.         if (=== strpos($dsn'amqp://')) {
  36.             $packageSuggestion ' Run "composer require symfony/amqp-messenger" to install AMQP transport.';
  37.         } elseif (=== strpos($dsn'doctrine://')) {
  38.             $packageSuggestion ' Run "composer require symfony/doctrine-messenger" to install Doctrine transport.';
  39.         } elseif (=== strpos($dsn'redis://') || === strpos($dsn'rediss://')) {
  40.             $packageSuggestion ' Run "composer require symfony/redis-messenger" to install Redis transport.';
  41.         } elseif (=== strpos($dsn'sqs://') || preg_match('#^https://sqs\.[\w\-]+\.amazonaws\.com/.+#'$dsn)) {
  42.             $packageSuggestion ' Run "composer require symfony/amazon-sqs-messenger" to install Amazon SQS transport.';
  43.         } elseif (=== strpos($dsn'beanstalkd://')) {
  44.             $packageSuggestion ' Run "composer require symfony/beanstalkd-messenger" to install Beanstalkd transport.';
  45.         }
  46.         throw new InvalidArgumentException('No transport supports the given Messenger DSN.'.$packageSuggestion);
  47.     }
  48.     public function supports(string $dsn, array $options): bool
  49.     {
  50.         foreach ($this->factories as $factory) {
  51.             if ($factory->supports($dsn$options)) {
  52.                 return true;
  53.             }
  54.         }
  55.         return false;
  56.     }
  57. }