-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathEnvelope.php
More file actions
66 lines (52 loc) · 1.62 KB
/
Copy pathEnvelope.php
File metadata and controls
66 lines (52 loc) · 1.62 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
64
65
66
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Message;
use function is_array;
abstract class Envelope implements EnvelopeInterface
{
/**
* @psalm-var array<string, mixed>|null
*/
private ?array $metadata = null;
public function __construct(protected MessageInterface $message) {}
/** @psalm-suppress MoreSpecificReturnType */
public static function fromData(string $type, mixed $data, array $metadata = []): static
{
/** @psalm-suppress LessSpecificReturnStatement */
return static::fromMessage(Message::fromData($type, $data, $metadata));
}
public function getMessage(): MessageInterface
{
return $this->message;
}
public function getType(): string
{
return $this->message->getType();
}
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;
}