|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Cubiche package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) Cubiche |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Cubiche\Domain\EventSourcing; |
|
13
|
|
|
|
|
14
|
|
|
use Cubiche\Domain\EventPublisher\DomainEvent as BaseDomainEvent; |
|
15
|
|
|
use Cubiche\Domain\Model\IdInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* DomainEvent class. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class DomainEvent extends BaseDomainEvent implements DomainEventInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var DomainEventId |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $eventId; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* EntityDomainEvent constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param IdInterface $aggregateId |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(IdInterface $aggregateId) |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct(); |
|
37
|
|
|
|
|
38
|
|
|
$this->setMetadata('aggregateId', $aggregateId); |
|
|
|
|
|
|
39
|
|
|
$this->setVersion(0); |
|
40
|
|
|
$this->eventId = DomainEventId::next(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
public function eventId() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->eventId; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function aggregateId() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->getMetadata('aggregateId'); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function version() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->getMetadata('version'); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setVersion($version) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->setMetadata('version', $version); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc} |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function fromArray(array $data) |
|
79
|
|
|
{ |
|
80
|
|
|
/** @var DomainEvent $domainEvent */ |
|
81
|
|
|
$domainEvent = parent::fromArray($data); |
|
|
|
|
|
|
82
|
|
|
$domainEvent->eventId = $data['eventId']; |
|
83
|
|
|
|
|
84
|
|
|
return $domainEvent; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritdoc} |
|
89
|
|
|
*/ |
|
90
|
|
|
public function toArray() |
|
91
|
|
|
{ |
|
92
|
|
|
return array_merge(parent::toArray(), array( |
|
|
|
|
|
|
93
|
|
|
'eventId' => $this->eventId(), |
|
94
|
|
|
)); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.