vendor/enqueue/dbal/DbalMessage.php line 9

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Enqueue\Dbal;
  4. use Interop\Queue\Message;
  5. class DbalMessage implements Message
  6. {
  7.     /**
  8.      * @var string
  9.      */
  10.     private $body;
  11.     /**
  12.      * @var array
  13.      */
  14.     private $properties;
  15.     /**
  16.      * @var array
  17.      */
  18.     private $headers;
  19.     /**
  20.      * @var bool
  21.      */
  22.     private $redelivered;
  23.     /**
  24.      * @var int
  25.      */
  26.     private $priority;
  27.     /**
  28.      * @var int milliseconds
  29.      */
  30.     private $deliveryDelay;
  31.     /**
  32.      * @var int seconds
  33.      */
  34.     private $redeliverAfter;
  35.     /**
  36.      * @var int milliseconds
  37.      */
  38.     private $timeToLive;
  39.     /**
  40.      * @var string|null
  41.      */
  42.     private $deliveryId;
  43.     /**
  44.      * @var string|null
  45.      */
  46.     private $queue;
  47.     /**
  48.      * Milliseconds, for example 15186054527288.
  49.      *
  50.      * Could be generated by the code: (int) (microtime(true) * 10000)
  51.      *
  52.      * @var int
  53.      */
  54.     private $publishedAt;
  55.     /**
  56.      * @param string $body
  57.      * @param array  $properties
  58.      * @param array  $headers
  59.      */
  60.     public function __construct(string $body '', array $properties = [], array $headers = [])
  61.     {
  62.         $this->body $body;
  63.         $this->properties $properties;
  64.         $this->headers $headers;
  65.         $this->redelivered false;
  66.         $this->priority null;
  67.         $this->deliveryDelay null;
  68.         $this->deliveryId null;
  69.         $this->redeliverAfter null;
  70.     }
  71.     public function setBody(string $body): void
  72.     {
  73.         $this->body $body;
  74.     }
  75.     public function getBody(): string
  76.     {
  77.         return $this->body;
  78.     }
  79.     public function setProperties(array $properties): void
  80.     {
  81.         $this->properties $properties;
  82.     }
  83.     public function setProperty(string $name$value): void
  84.     {
  85.         $this->properties[$name] = $value;
  86.     }
  87.     public function getProperties(): array
  88.     {
  89.         return $this->properties;
  90.     }
  91.     public function getProperty(string $name$default null)
  92.     {
  93.         return array_key_exists($name$this->properties) ? $this->properties[$name] : $default;
  94.     }
  95.     public function setHeader(string $name$value): void
  96.     {
  97.         $this->headers[$name] = $value;
  98.     }
  99.     public function setHeaders(array $headers): void
  100.     {
  101.         $this->headers $headers;
  102.     }
  103.     public function getHeaders(): array
  104.     {
  105.         return $this->headers;
  106.     }
  107.     public function getHeader(string $name$default null)
  108.     {
  109.         return array_key_exists($name$this->headers) ? $this->headers[$name] : $default;
  110.     }
  111.     public function isRedelivered(): bool
  112.     {
  113.         return $this->redelivered;
  114.     }
  115.     public function setRedelivered(bool $redelivered): void
  116.     {
  117.         $this->redelivered $redelivered;
  118.     }
  119.     public function setReplyTo(string $replyTo null): void
  120.     {
  121.         $this->setHeader('reply_to'$replyTo);
  122.     }
  123.     public function getReplyTo(): ?string
  124.     {
  125.         return $this->getHeader('reply_to');
  126.     }
  127.     public function getPriority(): ?int
  128.     {
  129.         return $this->priority;
  130.     }
  131.     public function setPriority(int $priority null): void
  132.     {
  133.         $this->priority $priority;
  134.     }
  135.     public function getDeliveryDelay(): ?int
  136.     {
  137.         return $this->deliveryDelay;
  138.     }
  139.     /**
  140.      * Set delay in milliseconds.
  141.      */
  142.     public function setDeliveryDelay(int $deliveryDelay null): void
  143.     {
  144.         $this->deliveryDelay $deliveryDelay;
  145.     }
  146.     /**
  147.      * @return int
  148.      */
  149.     public function getTimeToLive(): ?int
  150.     {
  151.         return $this->timeToLive;
  152.     }
  153.     /**
  154.      * Set time to live in milliseconds.
  155.      */
  156.     public function setTimeToLive(int $timeToLive null): void
  157.     {
  158.         $this->timeToLive $timeToLive;
  159.     }
  160.     public function setCorrelationId(string $correlationId null): void
  161.     {
  162.         $this->setHeader('correlation_id'$correlationId);
  163.     }
  164.     public function getCorrelationId(): ?string
  165.     {
  166.         return $this->getHeader('correlation_id'null);
  167.     }
  168.     public function setMessageId(string $messageId null): void
  169.     {
  170.         $this->setHeader('message_id'$messageId);
  171.     }
  172.     public function getMessageId(): ?string
  173.     {
  174.         return $this->getHeader('message_id'null);
  175.     }
  176.     public function getTimestamp(): ?int
  177.     {
  178.         $value $this->getHeader('timestamp');
  179.         return null === $value null $value;
  180.     }
  181.     public function setTimestamp(int $timestamp null): void
  182.     {
  183.         $this->setHeader('timestamp'$timestamp);
  184.     }
  185.     public function getDeliveryId(): ?string
  186.     {
  187.         return $this->deliveryId;
  188.     }
  189.     public function setDeliveryId(?string $deliveryId null): void
  190.     {
  191.         $this->deliveryId $deliveryId;
  192.     }
  193.     public function getRedeliverAfter(): int
  194.     {
  195.         return $this->redeliverAfter;
  196.     }
  197.     public function setRedeliverAfter(int $redeliverAfter null): void
  198.     {
  199.         $this->redeliverAfter $redeliverAfter;
  200.     }
  201.     public function getPublishedAt(): ?int
  202.     {
  203.         return $this->publishedAt;
  204.     }
  205.     public function setPublishedAt(int $publishedAt null): void
  206.     {
  207.         $this->publishedAt $publishedAt;
  208.     }
  209.     public function getQueue(): ?string
  210.     {
  211.         return $this->queue;
  212.     }
  213.     public function setQueue(?string $queue): void
  214.     {
  215.         $this->queue $queue;
  216.     }
  217. }