-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathEnvelope.php
More file actions
63 lines (50 loc) · 1.57 KB
/
Copy pathEnvelope.php
File metadata and controls
63 lines (50 loc) · 1.57 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Message;
abstract class Envelope implements EnvelopeInterface
{
private ?array $metadata = null;
public function __construct(protected MessageInterface $message)
{
}
/** @psalm-suppress MoreSpecificReturnType */
public static function fromData(string $handlerName, mixed $data, array $metadata = []): static
{
/** @psalm-suppress LessSpecificReturnStatement */
return static::fromMessage(Message::fromData($handlerName, $data, $metadata));
}
public function getMessage(): MessageInterface
{
return $this->message;
}
public function getHandlerName(): string
{
return $this->message->getHandlerName();
}
public function getData(): mixed
{
return $this->message->getData();
}
public function getMetadata(): array
{
if ($this->metadata === null) {
$messageMeta = $this->message->getMetadata();
$stack = $messageMeta[EnvelopeInterface::ENVELOPE_STACK_KEY] ?? [];
if (!is_array($stack)) {
$stack = [];
}
$this->metadata = array_merge(
$messageMeta,
[
EnvelopeInterface::ENVELOPE_STACK_KEY => array_merge(
$stack,
[static::class],
),
],
$this->getEnvelopeMetadata(),
);
}
return $this->metadata;
}
abstract protected function getEnvelopeMetadata(): array;
}