vendor/symfony/messenger/Middleware/FailedMessageProcessingMiddleware.php line 23

Open in your IDE?
  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\Middleware;
  11. use Symfony\Component\Messenger\Envelope;
  12. use Symfony\Component\Messenger\Stamp\ReceivedStamp;
  13. use Symfony\Component\Messenger\Stamp\SentToFailureTransportStamp;
  14. /**
  15.  * @author Ryan Weaver <ryan@symfonycasts.com>
  16.  */
  17. class FailedMessageProcessingMiddleware implements MiddlewareInterface
  18. {
  19.     public function handle(Envelope $envelopeStackInterface $stack): Envelope
  20.     {
  21.         // look for "received" messages decorated with the SentToFailureTransportStamp
  22.         /** @var SentToFailureTransportStamp|null $sentToFailureStamp */
  23.         $sentToFailureStamp $envelope->last(SentToFailureTransportStamp::class);
  24.         if (null !== $sentToFailureStamp && null !== $envelope->last(ReceivedStamp::class)) {
  25.             // mark the message as "received" from the original transport
  26.             // this guarantees the same behavior as when originally received
  27.             $envelope $envelope->with(new ReceivedStamp($sentToFailureStamp->getOriginalReceiverName()));
  28.         }
  29.         return $stack->next()->handle($envelope$stack);
  30.     }
  31. }