|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace EventSauce\EventSourcing; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
|
8
|
|
|
use RuntimeException; |
|
9
|
|
|
|
|
10
|
|
|
final class Message |
|
11
|
|
|
{ |
|
12
|
|
|
public const TIME_OF_RECORDING_FORMAT = 'Y-m-d H:i:s.uO'; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(private object $event, private array $headers = []) |
|
15
|
|
|
{ |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function withHeader(string $key, int|string|null|AggregateRootId $value): Message |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
$clone = clone $this; |
|
21
|
25 |
|
$clone->headers[$key] = $value; |
|
22
|
|
|
|
|
23
|
25 |
|
return $clone; |
|
24
|
25 |
|
} |
|
25
|
25 |
|
|
|
26
|
|
|
public function withHeaders(array $headers): Message |
|
27
|
|
|
{ |
|
28
|
|
|
$clone = clone $this; |
|
29
|
|
|
$clone->headers = $headers + $clone->headers; |
|
30
|
5 |
|
|
|
31
|
|
|
return $clone; |
|
32
|
5 |
|
} |
|
33
|
5 |
|
|
|
34
|
|
|
public function withTimeOfRecording(DateTimeImmutable $timeOfRecording): Message |
|
35
|
5 |
|
{ |
|
36
|
|
|
return $this->withHeader(Header::TIME_OF_RECORDING, $timeOfRecording->format(self::TIME_OF_RECORDING_FORMAT)); |
|
37
|
|
|
} |
|
38
|
14 |
|
|
|
39
|
|
|
public function aggregateVersion(): int |
|
40
|
14 |
|
{ |
|
41
|
14 |
|
$version = $this->headers[Header::AGGREGATE_ROOT_VERSION] ?? null; |
|
42
|
|
|
|
|
43
|
14 |
|
if (null === $version) { |
|
44
|
|
|
throw new RuntimeException("Can't get the version if the message has none."); |
|
45
|
|
|
} |
|
46
|
7 |
|
|
|
47
|
|
|
return (int) $version; |
|
48
|
7 |
|
} |
|
49
|
|
|
|
|
50
|
7 |
|
public function aggregateRootId(): ?AggregateRootId |
|
51
|
1 |
|
{ |
|
52
|
|
|
return $this->headers[Header::AGGREGATE_ROOT_ID] ?? null; |
|
53
|
|
|
} |
|
54
|
6 |
|
|
|
55
|
|
|
public function timeOfRecording(): DateTimeImmutable |
|
56
|
|
|
{ |
|
57
|
1 |
|
/* @var DateTimeImmutable */ |
|
58
|
|
|
$timeOfRecording = DateTimeImmutable::createFromFormat( |
|
59
|
1 |
|
self::TIME_OF_RECORDING_FORMAT, |
|
60
|
|
|
$header = ($this->headers[Header::TIME_OF_RECORDING] ?? '') |
|
61
|
|
|
); |
|
62
|
1 |
|
|
|
63
|
|
|
if ( ! $timeOfRecording instanceof DateTimeImmutable) { |
|
|
|
|
|
|
64
|
1 |
|
throw UnableToResolveTimeOfRecording::fromFormatAndHeader(self::TIME_OF_RECORDING_FORMAT, $header); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $timeOfRecording; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
9 |
|
public function header(string $key): int|string|array|AggregateRootId|null |
|
71
|
|
|
{ |
|
72
|
9 |
|
return $this->headers[$key] ?? null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
12 |
|
public function headers(): array |
|
76
|
|
|
{ |
|
77
|
12 |
|
return $this->headers; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
20 |
|
public function event(): object |
|
81
|
|
|
{ |
|
82
|
20 |
|
return $this->event; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths