1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Place\Events; |
4
|
|
|
|
5
|
|
|
use CultuurNet\UDB3\Address\Address; |
6
|
|
|
use CultuurNet\UDB3\Calendar; |
7
|
|
|
use CultuurNet\UDB3\CalendarInterface; |
8
|
|
|
use CultuurNet\UDB3\Event\EventType; |
9
|
|
|
use CultuurNet\UDB3\Language; |
10
|
|
|
use CultuurNet\UDB3\Place\PlaceEvent; |
11
|
|
|
use CultuurNet\UDB3\Theme; |
12
|
|
|
use CultuurNet\UDB3\Title; |
13
|
|
|
use DateTimeImmutable; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Event when a place is created. |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
class PlaceCreated extends PlaceEvent |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var Language |
22
|
|
|
*/ |
23
|
|
|
private $mainLanguage; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Title |
27
|
|
|
*/ |
28
|
|
|
private $title; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var EventType |
32
|
|
|
*/ |
33
|
|
|
private $eventType; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Theme |
37
|
|
|
*/ |
38
|
|
|
private $theme = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Address |
42
|
|
|
*/ |
43
|
|
|
private $address; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var CalendarInterface |
47
|
|
|
*/ |
48
|
|
|
private $calendar; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var DateTimeImmutable|null |
52
|
|
|
*/ |
53
|
|
|
private $publicationDate = null; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $placeId |
57
|
|
|
* @param Language $mainLanguage |
58
|
|
|
* @param Title $title |
59
|
|
|
* @param EventType $eventType |
60
|
|
|
* @param Address $address |
61
|
|
|
* @param CalendarInterface $calendar |
62
|
|
|
* @param Theme|null $theme |
63
|
|
|
* @param DateTimeImmutable|null $publicationDate |
64
|
|
|
*/ |
65
|
|
|
public function __construct( |
66
|
|
|
$placeId, |
67
|
|
|
Language $mainLanguage, |
68
|
|
|
Title $title, |
69
|
|
|
EventType $eventType, |
70
|
|
|
Address $address, |
71
|
|
|
CalendarInterface $calendar, |
72
|
|
|
Theme $theme = null, |
73
|
|
|
DateTimeImmutable $publicationDate = null |
74
|
|
|
) { |
75
|
|
|
parent::__construct($placeId); |
76
|
|
|
|
77
|
|
|
$this->mainLanguage = $mainLanguage; |
78
|
|
|
$this->title = $title; |
79
|
|
|
$this->eventType = $eventType; |
80
|
|
|
$this->address = $address; |
81
|
|
|
$this->calendar = $calendar; |
82
|
|
|
$this->theme = $theme; |
83
|
|
|
$this->publicationDate = $publicationDate; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return Language |
88
|
|
|
*/ |
89
|
|
|
public function getMainLanguage() |
90
|
|
|
{ |
91
|
|
|
return $this->mainLanguage; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return Title |
96
|
|
|
*/ |
97
|
|
|
public function getTitle() |
98
|
|
|
{ |
99
|
|
|
return $this->title; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return EventType |
104
|
|
|
*/ |
105
|
|
|
public function getEventType() |
106
|
|
|
{ |
107
|
|
|
return $this->eventType; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return Theme |
112
|
|
|
*/ |
113
|
|
|
public function getTheme() |
114
|
|
|
{ |
115
|
|
|
return $this->theme; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return CalendarInterface |
120
|
|
|
*/ |
121
|
|
|
public function getCalendar() |
122
|
|
|
{ |
123
|
|
|
return $this->calendar; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return Address |
128
|
|
|
*/ |
129
|
|
|
public function getAddress() |
130
|
|
|
{ |
131
|
|
|
return $this->address; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return DateTimeImmutable|null |
136
|
|
|
*/ |
137
|
|
|
public function getPublicationDate() |
138
|
|
|
{ |
139
|
|
|
return $this->publicationDate; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return array |
144
|
|
|
*/ |
145
|
|
|
public function serialize() |
146
|
|
|
{ |
147
|
|
|
$theme = null; |
148
|
|
|
if ($this->getTheme() !== null) { |
149
|
|
|
$theme = $this->getTheme()->serialize(); |
150
|
|
|
} |
151
|
|
|
$publicationDate = null; |
152
|
|
|
if (!is_null($this->getPublicationDate())) { |
153
|
|
|
$publicationDate = $this->getPublicationDate()->format(\DateTime::ATOM); |
154
|
|
|
} |
155
|
|
|
return parent::serialize() + array( |
156
|
|
|
'main_language' => $this->mainLanguage->getCode(), |
157
|
|
|
'title' => (string) $this->getTitle(), |
158
|
|
|
'event_type' => $this->getEventType()->serialize(), |
159
|
|
|
'theme' => $theme, |
160
|
|
|
'address' => $this->getAddress()->serialize(), |
161
|
|
|
'calendar' => $this->getCalendar()->serialize(), |
162
|
|
|
'publication_date' => $publicationDate, |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return static |
168
|
|
|
*/ |
169
|
|
|
public static function deserialize(array $data) |
170
|
|
|
{ |
171
|
|
|
$theme = null; |
172
|
|
|
if (!empty($data['theme'])) { |
173
|
|
|
$theme = Theme::deserialize($data['theme']); |
174
|
|
|
} |
175
|
|
|
$publicationDate = null; |
176
|
|
|
if (!empty($data['publication_date'])) { |
177
|
|
|
$publicationDate = DateTimeImmutable::createFromFormat( |
178
|
|
|
\DateTime::ATOM, |
179
|
|
|
$data['publication_date'] |
180
|
|
|
); |
181
|
|
|
} |
182
|
|
|
return new static( |
183
|
|
|
$data['place_id'], |
184
|
|
|
new Language($data['main_language']), |
185
|
|
|
new Title($data['title']), |
186
|
|
|
EventType::deserialize($data['event_type']), |
187
|
|
|
Address::deserialize($data['address']), |
188
|
|
|
Calendar::deserialize($data['calendar']), |
189
|
|
|
$theme, |
190
|
|
|
$publicationDate |
191
|
|
|
); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
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.