Conditions | 4 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
24 | public function handle(EnvelopeInterface $envelope): bool |
||
25 | { |
||
26 | $commit = $envelope->getMessage(); |
||
27 | Assertion::implementsInterface($commit, CommitInterface::class); |
||
28 | |||
29 | $metadata = $envelope->getMetadata(); |
||
30 | foreach ($commit->getEventLog() as $domainEvent) { |
||
31 | $fqcn = $domainEvent->getAggregateRootClass(); |
||
32 | $aggregateAlias = $fqcn::getAlias(); |
||
33 | $projectors = $this->projectorMap->filterByAggregateAlias($aggregateAlias); |
||
34 | foreach ($projectors->getIterator() as $projector) { |
||
35 | if (!$projector->handle($envelope)) { |
||
36 | throw new ReadModelException('Projector %s failed to handle message.'); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | $metadata = $metadata->with('_aggregate_alias', $aggregateAlias->toNative()); |
||
41 | $this->messageBus->publish($domainEvent, 'events', $metadata); |
||
42 | } |
||
43 | |||
44 | return true; |
||
45 | } |
||
46 | } |
||
47 |