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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Gos\Bundle\WebSocketBundle\Pusher;
  3. use Gos\Bundle\WebSocketBundle\DataCollector\WebsocketDataCollector;
  4. use Symfony\Component\Stopwatch\Stopwatch;
  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.', DataCollectingPusherDecorator::class);
  6. /**
  7. * @deprecated to be removed in 4.0, use the symfony/messenger component instead
  8. */
  9. final class DataCollectingPusherDecorator implements PusherInterface
  10. {
  11. private PusherInterface $pusher;
  12. private Stopwatch $stopwatch;
  13. private WebsocketDataCollector $dataCollector;
  14. public function __construct(PusherInterface $pusher, Stopwatch $stopwatch, WebsocketDataCollector $dataCollector)
  15. {
  16. $this->pusher = $pusher;
  17. $this->stopwatch = $stopwatch;
  18. $this->dataCollector = $dataCollector;
  19. }
  20. /**
  21. * @param string|array $data
  22. */
  23. public function push($data, string $routeName, array $routeParameters = [], array $context = []): void
  24. {
  25. $eventName = 'push.'.$this->getName();
  26. $this->stopwatch->start($eventName, 'websocket');
  27. $this->pusher->push($data, $routeName, $routeParameters, $context);
  28. $this->stopwatch->stop($eventName);
  29. $this->dataCollector->collectData($this->stopwatch->getEvent($eventName), $this->getName());
  30. }
  31. public function close(): void
  32. {
  33. $this->pusher->close();
  34. }
  35. public function setName(string $name): void
  36. {
  37. $this->pusher->setName($name);
  38. }
  39. public function getName(): string
  40. {
  41. return $this->pusher->getName();
  42. }
  43. }