vendor/gos/web-socket-bundle/src/Pusher/AbstractPusher.php line 8

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Gos\Bundle\WebSocketBundle\Pusher;
  3. use Gos\Bundle\WebSocketBundle\Router\WampRouter;
  4. use Symfony\Component\Serializer\SerializerInterface;
  5. 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.', AbstractPusher::class);
  6. /**
  7. * @deprecated to be removed in 4.0, use the symfony/messenger component instead
  8. */
  9. abstract class AbstractPusher implements PusherInterface
  10. {
  11. protected SerializerInterface $serializer;
  12. protected WampRouter $router;
  13. protected bool $connected = false;
  14. protected string $name = '';
  15. public function __construct(WampRouter $router, SerializerInterface $serializer)
  16. {
  17. $this->router = $router;
  18. $this->serializer = $serializer;
  19. }
  20. /**
  21. * @param array|string $data
  22. */
  23. public function push($data, string $routeName, array $routeParameters = [], array $context = []): void
  24. {
  25. $channel = $this->router->generate($routeName, $routeParameters);
  26. if (\is_string($data)) {
  27. $data = [$data];
  28. } elseif (!\is_array($data)) {
  29. throw new \InvalidArgumentException(sprintf('The $data argument of %s() must be a string or array, a %s was given.', __METHOD__, \gettype($data)));
  30. }
  31. $this->doPush(new Message($channel, $data), $context);
  32. }
  33. abstract protected function doPush(Message $message, array $context): void;
  34. public function isConnected(): bool
  35. {
  36. return $this->connected;
  37. }
  38. public function setConnected(bool $bool = true): void
  39. {
  40. $this->connected = $bool;
  41. }
  42. public function getName(): string
  43. {
  44. return $this->name;
  45. }
  46. public function setName(string $name): void
  47. {
  48. $this->name = $name;
  49. }
  50. }