vendor/gos/web-socket-bundle/src/Pusher/Wamp/WampPusher.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Gos\Bundle\WebSocketBundle\Pusher\Wamp;
  3. use Gos\Bundle\WebSocketBundle\Pusher\AbstractPusher;
  4. use Gos\Bundle\WebSocketBundle\Pusher\Message;
  5. use Gos\Bundle\WebSocketBundle\Router\WampRouter;
  6. use Gos\Component\WebSocketClient\Wamp\ClientInterface;
  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.', WampPusher::class);
  9. /**
  10. * @deprecated to be removed in 4.0, use the symfony/messenger component instead
  11. */
  12. final class WampPusher extends AbstractPusher
  13. {
  14. private ClientInterface $connection;
  15. private WampConnectionFactoryInterface $connectionFactory;
  16. public function __construct(
  17. WampRouter $router,
  18. SerializerInterface $serializer,
  19. WampConnectionFactoryInterface $connectionFactory
  20. ) {
  21. parent::__construct($router, $serializer);
  22. $this->connectionFactory = $connectionFactory;
  23. }
  24. protected function doPush(Message $message, array $context): void
  25. {
  26. if (false === $this->isConnected()) {
  27. $this->connection = $this->connectionFactory->createConnection();
  28. $this->connection->connect();
  29. $this->setConnected();
  30. }
  31. $this->connection->publish($message->getTopic(), $this->serializer->serialize($message->getData(), 'json'));
  32. }
  33. public function close(): void
  34. {
  35. if (false === $this->isConnected()) {
  36. return;
  37. }
  38. $this->connection->disconnect();
  39. }
  40. }