-
Notifications
You must be signed in to change notification settings - Fork 42
/
AggregateRootDecorator.php
79 lines (66 loc) · 2.02 KB
/
AggregateRootDecorator.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* This file is part of prooph/event-sourcing.
* (c) 2014-2021 Alexander Miertsch <kontakt@codeliner.ws>
* (c) 2015-2021 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Prooph\EventSourcing\EventStoreIntegration;
use BadMethodCallException;
use Iterator;
use Prooph\EventSourcing\AggregateChanged;
use Prooph\EventSourcing\AggregateRoot;
use RuntimeException;
class AggregateRootDecorator extends AggregateRoot
{
public static function newInstance(): self
{
return new static();
}
public function extractAggregateVersion(AggregateRoot $anAggregateRoot): int
{
return $anAggregateRoot->version;
}
/**
* @param AggregateRoot $anAggregateRoot
*
* @return \Prooph\EventSourcing\AggregateChanged[]
*/
public function extractRecordedEvents(AggregateRoot $anAggregateRoot): array
{
return $anAggregateRoot->popRecordedEvents();
}
public function extractAggregateId(AggregateRoot $anAggregateRoot): string
{
return $anAggregateRoot->aggregateId();
}
/**
* @throws RuntimeException
*/
public function fromHistory($arClass, Iterator $aggregateChangedEvents): AggregateRoot
{
if (! \class_exists($arClass)) {
throw new RuntimeException(
\sprintf('Aggregate root class %s cannot be found', $arClass)
);
}
return $arClass::reconstituteFromHistory($aggregateChangedEvents);
}
public function replayStreamEvents(AggregateRoot $aggregateRoot, Iterator $events): void
{
$aggregateRoot->replay($events);
}
/**
* @throws BadMethodCallException
*/
protected function aggregateId(): string
{
throw new BadMethodCallException('The AggregateRootDecorator does not have an id');
}
protected function apply(AggregateChanged $e): void
{
}
}