RedeliveryStamp.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Stamp;
  11. use Symfony\Component\ErrorHandler\Exception\FlattenException;
  12. use Symfony\Component\Messenger\Envelope;
  13. /**
  14. * Stamp applied when a messages needs to be redelivered.
  15. */
  16. final class RedeliveryStamp implements StampInterface
  17. {
  18. private $retryCount;
  19. private $redeliveredAt;
  20. private $exceptionMessage;
  21. private $flattenException;
  22. public function __construct(int $retryCount, string $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
  23. {
  24. $this->retryCount = $retryCount;
  25. $this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();
  26. if (null !== $exceptionMessage) {
  27. trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$exceptionMessage" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
  28. }
  29. $this->exceptionMessage = $exceptionMessage;
  30. if (null !== $flattenException) {
  31. trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$flattenException" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
  32. }
  33. $this->flattenException = $flattenException;
  34. }
  35. public static function getRetryCountFromEnvelope(Envelope $envelope): int
  36. {
  37. /** @var self|null $retryMessageStamp */
  38. $retryMessageStamp = $envelope->last(self::class);
  39. return $retryMessageStamp ? $retryMessageStamp->getRetryCount() : 0;
  40. }
  41. public function getRetryCount(): int
  42. {
  43. return $this->retryCount;
  44. }
  45. /**
  46. * @deprecated since Symfony 5.2, use ErrorDetailsStamp instead.
  47. */
  48. public function getExceptionMessage(): ?string
  49. {
  50. trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "getExceptionMessage()" method of the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
  51. return $this->exceptionMessage;
  52. }
  53. /**
  54. * @deprecated since Symfony 5.2, use ErrorDetailsStamp instead.
  55. */
  56. public function getFlattenException(): ?FlattenException
  57. {
  58. trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "getFlattenException()" method of the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
  59. return $this->flattenException;
  60. }
  61. public function getRedeliveredAt(): \DateTimeInterface
  62. {
  63. return $this->redeliveredAt;
  64. }
  65. }