-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathEnvelopeTrait.php
62 lines (50 loc) · 1.41 KB
/
EnvelopeTrait.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Message;
trait EnvelopeTrait
{
private MessageInterface $message;
/**
* A mirror of {@see MessageInterface::fromData()}
*/
abstract public static function fromMessage(MessageInterface $message): self;
public static function fromData(string $handlerName, mixed $data, array $metadata = []): MessageInterface
{
return self::fromMessage(Message::fromData($handlerName, $data, $metadata));
}
public function getMessage(): MessageInterface
{
return $this->message;
}
public function withMessage(MessageInterface $message): self
{
$instance = clone $this;
$instance->message = $message;
return $instance;
}
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(),
[
self::ENVELOPE_STACK_KEY => array_merge(
$this->message->getMetadata()[self::ENVELOPE_STACK_KEY] ?? [],
[self::class],
),
],
$this->getEnvelopeMetadata(),
);
}
public function getEnvelopeMetadata(): array
{
return [];
}
}