Completed
Push — master ( 3ad4be...2448d5 )
by David
05:51
created

EventPublishingEventStore::retrieve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Rawkode\Eidetic\EventStore;
4
5
use Rawkode\Eidetic\EventSourcing\EventSourcedEntity;
6
7
/**
8
 *
9
 */
10
final class EventPublishingEventStore implements EventStore
11
{
12
    /**
13
     * @var EventStore
14
     */
15
    private $eventStore;
16
17
    /**
18
     * @var EventPublisher
19
     */
20
    private $eventPublisher;
21
22
    /**
23
     * @param EventStore     $eventStore
24
     * @param EventPublisher $eventPublisher
25
     */
26
    public function __construct(EventStore $eventStore, EventPublisher $eventPublisher)
27
    {
28
        $this->eventStore = $eventStore;
29
        $this->eventPublisher = $eventPublisher;
30
    }
31
32
    /**
33
     * @param EventSourcedEntity $eventSourcedEntity
34
     */
35
    public function store(EventSourcedEntity $eventSourcedEntity)
36
    {
37
        $stagedEvents = $eventSourcedEntity->stagedEvents();
38
39
        $this->eventStore->store($eventSourcedEntity->identifier(), $eventSourcedEntity->stagedEvents());
40
41
        $this->publish($stagedEvents);
42
    }
43
44
    /**
45
     * @param string $identifier
46
     *
47
     * @return array
48
     */
49
    public function retrieve($identifier)
50
    {
51
        return $this->eventStore->retrieve($identifier);
52
    }
53
54
    /**
55
     * @param string $identifier
56
     *
57
     * @return array
58
     */
59
    public function retrieveLogs($identifier)
60
    {
61
        return $this->eventStore->retrieveLogs($identifier);
62
    }
63
64
    /**
65
     * @param array $events
66
     */
67
    private function publish(array $events)
68
    {
69
        foreach ($events as $event) {
70
            $this->eventPublisher->publish($event);
71
        }
72
    }
73
}
74