-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathIdEnvelope.php
More file actions
35 lines (28 loc) · 828 Bytes
/
IdEnvelope.php
File metadata and controls
35 lines (28 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Message;
/**
* ID envelope allows to identify a message.
*/
final class IdEnvelope extends Envelope
{
public const MESSAGE_ID_KEY = 'yii-message-id';
public function __construct(
MessageInterface $message,
private readonly string|int|null $id,
) {
parent::__construct($message);
}
public static function fromMessage(MessageInterface $message): self
{
return new self($message, $message->getMetadata()[self::MESSAGE_ID_KEY] ?? null);
}
public function getId(): string|int|null
{
return $this->id ?? $this->message->getMetadata()[self::MESSAGE_ID_KEY] ?? null;
}
protected function getEnvelopeMetadata(): array
{
return [self::MESSAGE_ID_KEY => $this->getId()];
}
}