1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Event\ReadModel\History; |
4
|
|
|
|
5
|
|
|
use Broadway\Domain\DomainMessage; |
6
|
|
|
use Broadway\EventHandling\EventListenerInterface; |
7
|
|
|
use CultuurNet\UDB3\Cdb\EventItemFactory; |
8
|
|
|
use CultuurNet\UDB3\Event\Events\DescriptionTranslated; |
9
|
|
|
use CultuurNet\UDB3\Event\Events\EventCopied; |
10
|
|
|
use CultuurNet\UDB3\Event\Events\EventImportedFromUDB2; |
11
|
|
|
use CultuurNet\UDB3\Event\Events\EventUpdatedFromUDB2; |
12
|
|
|
use CultuurNet\UDB3\Event\Events\LabelAdded; |
13
|
|
|
use CultuurNet\UDB3\Event\Events\LabelRemoved; |
14
|
|
|
use CultuurNet\UDB3\Event\Events\TitleTranslated; |
15
|
|
|
use CultuurNet\UDB3\Offer\ReadModel\History\OfferHistoryProjector; |
16
|
|
|
use ValueObjects\StringLiteral\StringLiteral; |
17
|
|
|
|
18
|
|
|
class HistoryProjector extends OfferHistoryProjector implements EventListenerInterface |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
protected function applyEventImportedFromUDB2( |
22
|
|
|
EventImportedFromUDB2 $eventImportedFromUDB2, |
23
|
|
|
DomainMessage $domainMessage |
24
|
|
|
) { |
25
|
|
|
$udb2Event = EventItemFactory::createEventFromCdbXml( |
26
|
|
|
$eventImportedFromUDB2->getCdbXmlNamespaceUri(), |
27
|
|
|
$eventImportedFromUDB2->getCdbXml() |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$this->writeHistory( |
31
|
|
|
$eventImportedFromUDB2->getEventId(), |
32
|
|
|
new Log( |
33
|
|
|
$this->dateFromUdb2DateString( |
34
|
|
|
$udb2Event->getCreationDate() |
35
|
|
|
), |
36
|
|
|
new StringLiteral('Aangemaakt in UDB2'), |
37
|
|
|
new StringLiteral($udb2Event->getCreatedBy()) |
38
|
|
|
) |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$this->writeHistory( |
42
|
|
|
$eventImportedFromUDB2->getEventId(), |
43
|
|
|
new Log( |
44
|
|
|
$this->domainMessageDateToNativeDate( |
45
|
|
|
$domainMessage->getRecordedOn() |
46
|
|
|
), |
47
|
|
|
new StringLiteral('Geïmporteerd vanuit UDB2') |
48
|
|
|
) |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function applyEventUpdatedFromUDB2( |
53
|
|
|
EventUpdatedFromUDB2 $eventUpdatedFromUDB2, |
54
|
|
|
DomainMessage $domainMessage |
55
|
|
|
) { |
56
|
|
|
$this->writeHistory( |
57
|
|
|
$eventUpdatedFromUDB2->getEventId(), |
58
|
|
|
new Log( |
59
|
|
|
$this->domainMessageDateToNativeDate($domainMessage->getRecordedOn()), |
60
|
|
|
new StringLiteral('Geüpdatet vanuit UDB2') |
61
|
|
|
) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param EventCopied $eventCopied |
67
|
|
|
* @param DomainMessage $domainMessage |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
protected function applyEventCopied( |
|
|
|
|
70
|
|
|
EventCopied $eventCopied, |
71
|
|
|
DomainMessage $domainMessage |
72
|
|
|
) { |
73
|
|
|
$this->writeHistory( |
74
|
|
|
$eventCopied->getItemId(), |
75
|
|
|
new Log( |
76
|
|
|
$this->domainMessageDateToNativeDate( |
77
|
|
|
$domainMessage->getRecordedOn() |
78
|
|
|
), |
79
|
|
|
new StringLiteral('Event gekopieerd van ' . $eventCopied->getOriginalEventId()), |
80
|
|
|
$this->getAuthorFromMetadata($domainMessage->getMetadata()) |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
protected function getLabelAddedClassName() |
89
|
|
|
{ |
90
|
|
|
return LabelAdded::class; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
protected function getLabelRemovedClassName() |
97
|
|
|
{ |
98
|
|
|
return LabelRemoved::class; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
protected function getTitleTranslatedClassName() |
105
|
|
|
{ |
106
|
|
|
return TitleTranslated::class; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
protected function getDescriptionTranslatedClassName() |
113
|
|
|
{ |
114
|
|
|
return DescriptionTranslated::class; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.