-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathEnvelope.php
48 lines (39 loc) · 1.17 KB
/
Envelope.php
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
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Message;
abstract class Envelope implements EnvelopeInterface
{
public function __construct(protected MessageInterface $message)
{
}
public static function fromData(string $handlerName, mixed $data, array $metadata = []): MessageInterface
{
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
{
return array_merge(
$this->message->getMetadata(),
[
EnvelopeInterface::ENVELOPE_STACK_KEY => array_merge(
$this->message->getMetadata()[EnvelopeInterface::ENVELOPE_STACK_KEY] ?? [],
[static::class],
),
],
$this->getEnvelopeMetadata(),
);
}
abstract protected function getEnvelopeMetadata(): array;
}