|
4 | 4 |
|
5 | 5 | namespace Yiisoft\Queue\Message; |
6 | 6 |
|
7 | | -final class Message implements MessageInterface |
| 7 | +abstract class Message implements MessageInterface |
8 | 8 | { |
9 | 9 | /** |
10 | | - * @param string $type A message type used to resolve the handler. |
11 | | - * @param mixed $data Message data, encodable by a queue adapter |
12 | | - * @param array $metadata Message metadata, encodable by a queue adapter |
13 | | - * |
14 | | - * @psalm-param array<string, mixed> $metadata |
| 10 | + * @psalm-var array<string, mixed> |
15 | 11 | */ |
16 | | - public function __construct( |
17 | | - private readonly string $type, |
18 | | - private readonly mixed $data, |
19 | | - private array $metadata = [], |
20 | | - ) {} |
| 12 | + private array $metadata = []; |
21 | 13 |
|
22 | | - public static function fromData(string $type, mixed $data, array $metadata = []): MessageInterface |
| 14 | + final public function getMetadata(): array |
23 | 15 | { |
24 | | - return new self($type, $data, $metadata); |
25 | | - } |
26 | | - |
27 | | - public function getType(): string |
28 | | - { |
29 | | - return $this->type; |
30 | | - } |
31 | | - |
32 | | - public function getData(): mixed |
33 | | - { |
34 | | - return $this->data; |
| 16 | + return $this->metadata; |
35 | 17 | } |
36 | 18 |
|
37 | | - public function getMetadata(): array |
| 19 | + final public function withMetadata(array $metadata): static |
38 | 20 | { |
39 | | - return $this->metadata; |
| 21 | + $new = clone $this; |
| 22 | + $new->metadata = $metadata; |
| 23 | + return $new; |
40 | 24 | } |
41 | 25 | } |
0 commit comments