vendor/symfony/amqp-messenger/Transport/AmqpStamp.php line 20

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\Bridge\Amqp\Transport;
  11. use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;
  12. /**
  13.  * @author Guillaume Gammelin <ggammelin@gmail.com>
  14.  * @author Samuel Roze <samuel.roze@gmail.com>
  15.  */
  16. final class AmqpStamp implements NonSendableStampInterface
  17. {
  18.     private $routingKey;
  19.     private $flags;
  20.     private $attributes;
  21.     private $isRetryAttempt false;
  22.     public function __construct(?string $routingKey nullint $flags = \AMQP_NOPARAM, array $attributes = [])
  23.     {
  24.         $this->routingKey $routingKey;
  25.         $this->flags $flags;
  26.         $this->attributes $attributes;
  27.     }
  28.     public function getRoutingKey(): ?string
  29.     {
  30.         return $this->routingKey;
  31.     }
  32.     public function getFlags(): int
  33.     {
  34.         return $this->flags;
  35.     }
  36.     public function getAttributes(): array
  37.     {
  38.         return $this->attributes;
  39.     }
  40.     public static function createFromAmqpEnvelope(\AMQPEnvelope $amqpEnvelope, ?self $previousStamp null, ?string $retryRoutingKey null): self
  41.     {
  42.         $attr $previousStamp->attributes ?? [];
  43.         $attr['headers'] = $attr['headers'] ?? $amqpEnvelope->getHeaders();
  44.         $attr['content_type'] = $attr['content_type'] ?? $amqpEnvelope->getContentType();
  45.         $attr['content_encoding'] = $attr['content_encoding'] ?? $amqpEnvelope->getContentEncoding();
  46.         $attr['delivery_mode'] = $attr['delivery_mode'] ?? $amqpEnvelope->getDeliveryMode();
  47.         $attr['priority'] = $attr['priority'] ?? $amqpEnvelope->getPriority();
  48.         $attr['timestamp'] = $attr['timestamp'] ?? $amqpEnvelope->getTimestamp();
  49.         $attr['app_id'] = $attr['app_id'] ?? $amqpEnvelope->getAppId();
  50.         $attr['message_id'] = $attr['message_id'] ?? $amqpEnvelope->getMessageId();
  51.         $attr['user_id'] = $attr['user_id'] ?? $amqpEnvelope->getUserId();
  52.         $attr['expiration'] = $attr['expiration'] ?? $amqpEnvelope->getExpiration();
  53.         $attr['type'] = $attr['type'] ?? $amqpEnvelope->getType();
  54.         $attr['reply_to'] = $attr['reply_to'] ?? $amqpEnvelope->getReplyTo();
  55.         $attr['correlation_id'] = $attr['correlation_id'] ?? $amqpEnvelope->getCorrelationId();
  56.         if (null === $retryRoutingKey) {
  57.             $stamp = new self($previousStamp->routingKey ?? $amqpEnvelope->getRoutingKey(), $previousStamp->flags ?? \AMQP_NOPARAM$attr);
  58.         } else {
  59.             $stamp = new self($retryRoutingKey$previousStamp->flags ?? \AMQP_NOPARAM$attr);
  60.             $stamp->isRetryAttempt true;
  61.         }
  62.         return $stamp;
  63.     }
  64.     public function isRetryAttempt(): bool
  65.     {
  66.         return $this->isRetryAttempt;
  67.     }
  68.     public static function createWithAttributes(array $attributes, ?self $previousStamp null): self
  69.     {
  70.         return new self(
  71.             $previousStamp->routingKey ?? null,
  72.             $previousStamp->flags ?? \AMQP_NOPARAM,
  73.             array_merge($previousStamp->attributes ?? [], $attributes)
  74.         );
  75.     }
  76. }
  77. if (!class_exists(\Symfony\Component\Messenger\Transport\AmqpExt\AmqpStamp::class, false)) {
  78.     class_alias(AmqpStamp::class, \Symfony\Component\Messenger\Transport\AmqpExt\AmqpStamp::class);
  79. }