1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Borobudur-Event-Sourcing package. |
4
|
|
|
* |
5
|
|
|
* (c) Hexacodelabs <http://hexacodelabs.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Borobudur\EventSourcing\Domain; |
12
|
|
|
|
13
|
|
|
use Borobudur\Cqrs\IdentifierInterface; |
14
|
|
|
use Borobudur\Cqrs\Message\DomainEventInterface; |
15
|
|
|
use DateTime; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Iqbal Maulana <[email protected]> |
19
|
|
|
* @created 8/20/15 |
20
|
|
|
*/ |
21
|
|
|
class DomainMessage implements DomainMessageInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
private $version; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var DateTime |
35
|
|
|
*/ |
36
|
|
|
private $created; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var DomainEventInterface |
40
|
|
|
*/ |
41
|
|
|
private $payload; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Constructor. |
45
|
|
|
* |
46
|
|
|
* @param mixed $id |
47
|
|
|
* @param int $version |
48
|
|
|
* @param DateTime $created |
49
|
|
|
* @param DomainEventInterface $payload |
50
|
|
|
*/ |
51
|
|
|
public function __construct($id, $version, DateTime $created, DomainEventInterface $payload) |
52
|
|
|
{ |
53
|
|
|
$this->id = $id; |
54
|
|
|
$this->version = $version; |
55
|
|
|
$this->created = $created; |
56
|
|
|
$this->payload = $payload; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Factory create domain message. |
61
|
|
|
* |
62
|
|
|
* @param IdentifierInterface $id |
63
|
|
|
* @param int $version |
64
|
|
|
* @param DomainEventInterface $payload |
65
|
|
|
* |
66
|
|
|
* @return static |
67
|
|
|
*/ |
68
|
|
|
public static function create(IdentifierInterface $id, $version, DomainEventInterface $payload) |
69
|
|
|
{ |
70
|
|
|
return new static($id, $version, new DateTime(), $payload); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function getId() |
77
|
|
|
{ |
78
|
|
|
return $this->id; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function getVersion() |
85
|
|
|
{ |
86
|
|
|
return $this->version; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function getType() |
93
|
|
|
{ |
94
|
|
|
return get_class($this->payload); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function getCreated() |
101
|
|
|
{ |
102
|
|
|
return $this->created; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function getPayload() |
109
|
|
|
{ |
110
|
|
|
return $this->payload; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|