-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathAbstractEnvelope.php
More file actions
69 lines (57 loc) · 1.83 KB
/
Copy pathAbstractEnvelope.php
File metadata and controls
69 lines (57 loc) · 1.83 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
67
68
69
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Message;
use Yiisoft\Arrays\ArrayHelper;
abstract class AbstractEnvelope implements EnvelopeInterface
{
protected array $metadata = [];
private MessageInterface $message;
public function __construct(MessageInterface $message)
{
$this->metadata = $message->getMetadata();
$envelopes = [static::class];
while ($message instanceof EnvelopeInterface) {
if ($message::class !== static::class) {
$envelopes = [$message::class];
}
$message = $message->getMessage();
}
$this->message = $message;
if (isset($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY]) && is_array($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY])) {
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = array_merge(
$envelopes,
array_filter(
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY],
static fn (string $envelope): bool => !in_array($envelope, $envelopes),
),
);
} else {
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = [static::class];
}
}
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 ArrayHelper::merge(
$this->metadata,
$this->getEnvelopeMetadata(),
);
}
/**
* Metadata of the envelope
*
* @return array
*/
abstract protected function getEnvelopeMetadata(): array;
}