1 | <?php |
||
15 | class DocumentPerEventStorageStrategy implements StorageStrategyInterface |
||
16 | { |
||
17 | |||
18 | const ORDER_ASC = 1; |
||
19 | const ORDER_DESC = -1; |
||
20 | |||
21 | /** |
||
22 | * Generates the DBObject instances that need to be stored for a commit. |
||
23 | * |
||
24 | * @param string $type The aggregate's type identifier |
||
25 | * @param SerializerInterface $eventSerializer The serializer to serialize events with |
||
26 | * @param DomainEventMessageInterface[] The messages contained in this commit |
||
27 | * @return array of DBObject, representing the documents to store |
||
28 | */ |
||
29 | 8 | public function createDocuments($type, SerializerInterface $eventSerializer, array $messages) |
|
39 | |||
40 | /** |
||
41 | * Extracts the individual Event Messages from the given <code>entry</code>. The <code>aggregateIdentifier</code> |
||
42 | * is passed to allow messages to contain the actual object, instead of its serialized form. The |
||
43 | * <code>serializer</code> and <code>upcasterChain</code> should be used to deserialize and upcast messages before |
||
44 | * returning them. |
||
45 | * |
||
46 | * @param array $entry The entry containing information of a stored commit |
||
47 | * @param string $aggregateIdentifier The aggregate identifier used to query events |
||
48 | * @param SerializerInterface $serializer The serializer to deserialize events with |
||
49 | * @param mixed $upcasterChain The upcaster chain to upcast stored events with // !!! TODO |
||
50 | * @param bool $skipUnknownTypes If unknown event types should be skipped |
||
51 | * @return DomainEventMessageInterface[] a list of messages contained in the entry |
||
52 | */ |
||
53 | 6 | public function extractEventMessages( |
|
68 | |||
69 | /** |
||
70 | * Provides a cursor for access to all events for an aggregate with given <code>aggregateType</code> and |
||
71 | * <code>aggregateIdentifier</code>, with a sequence number equal or higher than the given |
||
72 | * <code>firstSequenceNumber</code>. The returned documents should be ordered chronologically (typically by using |
||
73 | * the sequence number). |
||
74 | * <p/> |
||
75 | * Each DBObject document returned as result of this cursor will be passed to {@link |
||
76 | * #extractEventMessages} in order to retrieve individual DomainEventMessages. |
||
77 | * |
||
78 | * @param \MongoCollection $collection The collection to |
||
79 | * @param string $aggregateType The type identifier of the aggregate to query |
||
80 | * @param string $aggregateIdentifier The identifier of the aggregate to query |
||
81 | * @param int $firstSequenceNumber The sequence number of the first event to return |
||
82 | * @return \MongoCursor a Query object that represent a query for events of an aggregate |
||
83 | */ |
||
84 | 6 | public function findEvents( |
|
94 | |||
95 | /** |
||
96 | * Find all events that match the given <code>criteria</code> in the given <code>collection</code> |
||
97 | * |
||
98 | * @param \MongoCollection $collection The collection to search for events |
||
99 | * @param array $criteria The criteria to match against the events |
||
100 | * @return \MongoCursor a cursor for the documents representing matched events |
||
101 | */ |
||
102 | 1 | public function findEventsByCriteria(\MongoCollection $collection, array $criteria = []) |
|
111 | |||
112 | /** |
||
113 | * Finds the entry containing the last snapshot event for an aggregate with given <code>aggregateType</code> and |
||
114 | * <code>aggregateIdentifier</code> in the given <code>collection</code>. For each result returned by the Cursor, |
||
115 | * an invocation to {@link #extractEventMessages} will be used to extract |
||
116 | * the actual DomainEventMessages. |
||
117 | * |
||
118 | * @param \MongoCollection $collection The collection to find the last snapshot event in |
||
119 | * @param string $aggregateType The type identifier of the aggregate to find a snapshot for |
||
120 | * @param string $aggregateIdentifier The identifier of the aggregate to find a snapshot for |
||
121 | * @return \MongoCursor a cursor providing access to the entries found |
||
122 | */ |
||
123 | 4 | public function findLastSnapshot(\MongoCollection $collection, $aggregateType, $aggregateIdentifier) |
|
134 | |||
135 | /** |
||
136 | * Ensure that the correct indexes are in place. |
||
137 | * |
||
138 | * @param \MongoCollection $eventsCollection The collection containing the documents representing commits and events. |
||
139 | * @param \MongoCollection $snapshotsCollection The collection containing the document representing snapshots |
||
140 | */ |
||
141 | 10 | public function ensureIndexes(\MongoCollection $eventsCollection, \MongoCollection $snapshotsCollection) |
|
178 | |||
179 | } |