|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* The software is based on the Axon Framework project which is |
|
17
|
|
|
* licensed under the Apache 2.0 license. For more information on the Axon Framework |
|
18
|
|
|
* see <http://www.axonframework.org/>. |
|
19
|
|
|
* |
|
20
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
21
|
|
|
* and is licensed under the MIT license. For more information, see |
|
22
|
|
|
* <http://www.governor-framework.org/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Governor\Framework\EventStore\Orm; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
28
|
|
|
use Governor\Framework\Domain\DomainEventMessageInterface; |
|
29
|
|
|
use Governor\Framework\Serializer\SerializedObjectInterface; |
|
30
|
|
|
use Governor\Framework\Serializer\SimpleSerializedObject; |
|
31
|
|
|
use Governor\Framework\Serializer\SimpleSerializedType; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Abstract base class that defines the ORM entry for storing events in the event store. |
|
35
|
|
|
* |
|
36
|
|
|
* @author "David Kalosi" <[email protected]> |
|
37
|
|
|
* @license <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> |
|
38
|
|
|
* @ORM\MappedSuperclass |
|
39
|
|
|
*/ |
|
40
|
|
|
abstract class AbstractEventEntry |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @ORM\Id |
|
45
|
|
|
* @ORM\Column(name="type", type="string") |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
private $type; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @ORM\Id |
|
52
|
|
|
* @ORM\Column(name="aggregate_id", type="string") |
|
53
|
|
|
* @var mixed |
|
54
|
|
|
*/ |
|
55
|
|
|
private $aggregateIdentifier; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @ORM\Id |
|
59
|
|
|
* @ORM\Column(name="scn", type="integer") |
|
60
|
|
|
* @var integer |
|
61
|
|
|
*/ |
|
62
|
|
|
private $scn; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @ORM\Column(name="event_id", type="string", unique=true) |
|
66
|
|
|
* @var string |
|
67
|
|
|
*/ |
|
68
|
|
|
private $eventIdentifier; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
|
72
|
|
|
* @var \DateTime |
|
73
|
|
|
*/ |
|
74
|
|
|
private $timestamp; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @ORM\Column(name="payload_type", type="string") |
|
78
|
|
|
* @var string |
|
79
|
|
|
*/ |
|
80
|
|
|
private $payloadType; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @ORM\Column(name="payload", type="text") |
|
84
|
|
|
* @var mixed |
|
85
|
|
|
*/ |
|
86
|
|
|
private $payload; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @ORM\Column(name="payload_revision", type="string", nullable=true) |
|
90
|
|
|
* @var string |
|
91
|
|
|
*/ |
|
92
|
|
|
private $payloadRevision; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @ORM\Column(name="metadata", type="text") |
|
96
|
|
|
* @var mixed |
|
97
|
|
|
*/ |
|
98
|
|
|
private $metaData; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Initialize an Event entry for the given <code>event</code>. |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $type The type identifier of the aggregate root the event belongs to |
|
104
|
|
|
* @param DomainEventMessageInterface $event The event to store in the EventStore |
|
105
|
|
|
* @param SerializedObjectInterface $payload The serialized payload of the Event |
|
106
|
|
|
* @param SerializedObjectInterface $metaData The serialized metaData of the Event |
|
107
|
|
|
*/ |
|
108
|
11 |
|
public function __construct($type, DomainEventMessageInterface $event, |
|
109
|
|
|
SerializedObjectInterface $payload, |
|
110
|
|
|
SerializedObjectInterface $metaData) |
|
111
|
|
|
{ |
|
112
|
11 |
|
$this->eventIdentifier = $event->getIdentifier(); |
|
113
|
11 |
|
$this->type = $type; |
|
114
|
|
|
//$this->payloadType = $payload->getContentType(); |
|
|
|
|
|
|
115
|
11 |
|
$this->payloadType = $payload->getType()->getName(); |
|
116
|
11 |
|
$this->payloadRevision = $payload->getType()->getRevision(); |
|
117
|
11 |
|
$this->payload = $payload->getData(); |
|
118
|
11 |
|
$this->aggregateIdentifier = $event->getAggregateIdentifier(); |
|
119
|
11 |
|
$this->scn = $event->getScn(); |
|
120
|
11 |
|
$this->metaData = $metaData->getData(); |
|
121
|
11 |
|
$this->timestamp = $event->getTimestamp(); |
|
122
|
11 |
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Returns the Aggregate Identifier of the associated event. |
|
126
|
|
|
* |
|
127
|
|
|
* @return mixed the Aggregate Identifier of the associated event. |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getAggregateIdentifier() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->aggregateIdentifier; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Returns the type identifier of the aggregate. |
|
136
|
|
|
* |
|
137
|
|
|
* @return string the type identifier of the aggregate. |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getType() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->type; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Returns the sequence number of the associated event. |
|
146
|
|
|
* |
|
147
|
|
|
* @return integer the sequence number of the associated event. |
|
148
|
|
|
*/ |
|
149
|
1 |
|
public function getScn() |
|
150
|
|
|
{ |
|
151
|
1 |
|
return $this->scn; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Returns the time stamp of the associated event. |
|
156
|
|
|
* |
|
157
|
|
|
* @return \DateTime the time stamp of the associated event. |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getTimestamp() |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->timestamp; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function getEventIdentifier() |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->eventIdentifier; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function getPayload() |
|
170
|
|
|
{ |
|
171
|
|
|
return new SimpleSerializedObject($this->payload, |
|
172
|
|
|
new SimpleSerializedType($this->payloadType, |
|
173
|
|
|
$this->payloadRevision)); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function getMetaData() |
|
177
|
|
|
{ |
|
178
|
|
|
return new SimpleSerializedObject($this->metaData, |
|
179
|
|
|
new SimpleSerializedType('Governor\Framework\Domain\Metadata')); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.