1 | <?php |
||
11 | final class Repository |
||
12 | { |
||
13 | /** @var $entityClass */ |
||
14 | private $entityClass; |
||
15 | |||
16 | /** @var EventStore $eventStore */ |
||
17 | private $eventStore; |
||
18 | |||
19 | /** |
||
20 | * @param string $class |
||
21 | * @param EventStore $eventStore |
||
22 | */ |
||
23 | private function __construct($class, EventStore $eventStore) |
||
28 | |||
29 | /** |
||
30 | * @param $class |
||
31 | * @param EventStore $eventStore |
||
32 | * @return Repository |
||
33 | */ |
||
34 | public static function createForWrites($class, EventStore $eventStore) |
||
38 | |||
39 | /** |
||
40 | * @param $key |
||
41 | * @return mixed |
||
42 | */ |
||
43 | public function load($key) |
||
44 | { |
||
45 | $events = $this->eventStore->retrieve($key); |
||
46 | |||
47 | return call_user_func(array($this->entityClass, 'initialise'), $events); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param EventSourcedEntity $eventSourcedEntity |
||
52 | * @throws IncorrectEntityClassException |
||
53 | */ |
||
54 | public function save(EventSourcedEntity $eventSourcedEntity) |
||
58 | } |
||
59 |