vendor/gos/web-socket-bundle/src/Pusher/Amqp/AmqpPusher.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Gos\Bundle\WebSocketBundle\Pusher\Amqp;
  3. use Gos\Bundle\WebSocketBundle\Pusher\AbstractPusher;
  4. use Gos\Bundle\WebSocketBundle\Pusher\Message;
  5. use Gos\Bundle\WebSocketBundle\Router\WampRouter;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. use Symfony\Component\Serializer\SerializerInterface;
  8. trigger_deprecation('gos/web-socket-bundle''3.1''The "%s" class is deprecated and will be removed in 4.0, use the symfony/messenger component instead.'AmqpPusher::class);
  9. /**
  10.  * @deprecated to be removed in 4.0, use the symfony/messenger component instead
  11.  */
  12. final class AmqpPusher extends AbstractPusher
  13. {
  14.     private \AMQPConnection $connection;
  15.     private \AMQPExchange $exchange;
  16.     private AmqpConnectionFactoryInterface $connectionFactory;
  17.     public function __construct(
  18.         WampRouter $router,
  19.         SerializerInterface $serializer,
  20.         AmqpConnectionFactoryInterface $connectionFactory
  21.     ) {
  22.         parent::__construct($router$serializer);
  23.         $this->connectionFactory $connectionFactory;
  24.     }
  25.     protected function doPush(Message $message, array $context): void
  26.     {
  27.         if (false === $this->connected) {
  28.             $this->connection $this->connectionFactory->createConnection();
  29.             $this->connection->connect();
  30.             $this->exchange $this->connectionFactory->createExchange($this->connection);
  31.             $this->setConnected();
  32.         }
  33.         $resolver = new OptionsResolver();
  34.         $resolver->setDefaults(
  35.             [
  36.                 'routing_key' => '',
  37.                 'publish_flags' => AMQP_NOPARAM,
  38.                 'attributes' => [],
  39.             ]
  40.         );
  41.         $context $resolver->resolve($context);
  42.         $this->exchange->publish(
  43.             $this->serializer->serialize($message'json'),
  44.             $context['routing_key'],
  45.             $context['publish_flags'],
  46.             $context['attributes']
  47.         );
  48.     }
  49.     public function close(): void
  50.     {
  51.         if (false === $this->isConnected()) {
  52.             return;
  53.         }
  54.         $this->connection->disconnect();
  55.     }
  56. }