SingleMessageReceiver.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Receiver;
  11. use Symfony\Component\Messenger\Envelope;
  12. /**
  13. * Receiver that decorates another, but receives only 1 specific message.
  14. *
  15. * @author Ryan Weaver <ryan@symfonycasts.com>
  16. *
  17. * @internal
  18. */
  19. class SingleMessageReceiver implements ReceiverInterface
  20. {
  21. private $receiver;
  22. private $envelope;
  23. private $hasReceived = false;
  24. public function __construct(ReceiverInterface $receiver, Envelope $envelope)
  25. {
  26. $this->receiver = $receiver;
  27. $this->envelope = $envelope;
  28. }
  29. public function get(): iterable
  30. {
  31. if ($this->hasReceived) {
  32. return [];
  33. }
  34. $this->hasReceived = true;
  35. return [$this->envelope];
  36. }
  37. public function ack(Envelope $envelope): void
  38. {
  39. $this->receiver->ack($envelope);
  40. }
  41. public function reject(Envelope $envelope): void
  42. {
  43. $this->receiver->reject($envelope);
  44. }
  45. }