|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Event\Events; |
|
4
|
|
|
|
|
5
|
|
|
use CultuurNet\UDB3\Calendar; |
|
6
|
|
|
use CultuurNet\UDB3\CalendarInterface; |
|
7
|
|
|
use CultuurNet\UDB3\EventSourcing\AggregateCopiedEventInterface; |
|
8
|
|
|
use CultuurNet\UDB3\Offer\Events\AbstractEvent; |
|
9
|
|
|
|
|
10
|
|
|
class EventCopied extends AbstractEvent implements AggregateCopiedEventInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
private $originalEventId; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var CalendarInterface|Calendar |
|
19
|
|
|
*/ |
|
20
|
|
|
private $calendar; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* EventCopied constructor. |
|
24
|
|
|
* @param string $eventId |
|
25
|
|
|
* @param string $originalEventId |
|
26
|
|
|
* @param CalendarInterface $calendar |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct( |
|
29
|
|
|
$eventId, |
|
30
|
|
|
$originalEventId, |
|
31
|
|
|
CalendarInterface $calendar |
|
32
|
|
|
) { |
|
33
|
|
|
parent::__construct($eventId); |
|
34
|
|
|
|
|
35
|
|
|
if (!is_string($originalEventId)) { |
|
36
|
|
|
throw new \InvalidArgumentException( |
|
37
|
|
|
'Expected originalEventId to be a string, received ' . gettype($originalEventId) |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$this->originalEventId = $originalEventId; |
|
42
|
|
|
$this->calendar = $calendar; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @inheritdoc |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getParentAggregateId() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->originalEventId; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getOriginalEventId() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->originalEventId; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return CalendarInterface |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getCalendar() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->calendar; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @inheritdoc |
|
71
|
|
|
*/ |
|
72
|
|
|
public function serialize() |
|
73
|
|
|
{ |
|
74
|
|
|
return parent::serialize() + [ |
|
75
|
|
|
'original_event_id' => $this->getOriginalEventId(), |
|
76
|
|
|
'calendar' => $this->calendar->serialize() |
|
|
|
|
|
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @inheritdoc |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function deserialize(array $data) |
|
84
|
|
|
{ |
|
85
|
|
|
return new static( |
|
86
|
|
|
$data['item_id'], |
|
87
|
|
|
$data['original_event_id'], |
|
88
|
|
|
Calendar::deserialize($data['calendar']) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: