AddBusNameStampMiddleware.php 963 B

123456789101112131415161718192021222324252627282930313233343536373839
  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\BusNameStamp;
  13. /**
  14. * Adds the BusNameStamp to the bus.
  15. *
  16. * @author Ryan Weaver <ryan@symfonycasts.com>
  17. */
  18. class AddBusNameStampMiddleware implements MiddlewareInterface
  19. {
  20. private $busName;
  21. public function __construct(string $busName)
  22. {
  23. $this->busName = $busName;
  24. }
  25. public function handle(Envelope $envelope, StackInterface $stack): Envelope
  26. {
  27. if (null === $envelope->last(BusNameStamp::class)) {
  28. $envelope = $envelope->with(new BusNameStamp($this->busName));
  29. }
  30. return $stack->next()->handle($envelope, $stack);
  31. }
  32. }