1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Media\Events; |
4
|
|
|
|
5
|
|
|
use Broadway\Serializer\SerializableInterface; |
6
|
|
|
use CultuurNet\UDB3\Language; |
7
|
|
|
use CultuurNet\UDB3\Media\Properties\MIMEType; |
8
|
|
|
use ValueObjects\Identity\UUID; |
9
|
|
|
use ValueObjects\StringLiteral\StringLiteral; |
10
|
|
|
use ValueObjects\Web\Url; |
11
|
|
|
|
12
|
|
|
class MediaObjectCreated implements SerializableInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var UUID |
16
|
|
|
*/ |
17
|
|
|
protected $mediaObjectId; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var MIMEType |
21
|
|
|
*/ |
22
|
|
|
protected $mimeType; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var String |
26
|
|
|
*/ |
27
|
|
|
protected $description; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var String |
31
|
|
|
*/ |
32
|
|
|
protected $copyrightHolder; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Url |
36
|
|
|
*/ |
37
|
|
|
protected $sourceLocation; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Language |
41
|
|
|
*/ |
42
|
|
|
protected $language; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* MediaObjectCreated constructor. |
46
|
|
|
* @param UUID $id |
47
|
|
|
* @param MIMEType $fileType |
48
|
|
|
* @param \ValueObjects\StringLiteral\StringLiteral $description |
49
|
|
|
* @param \ValueObjects\StringLiteral\StringLiteral $copyrightHolder |
50
|
|
|
* @param Language $language |
51
|
|
|
* @param Url $sourceLocation |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
54
|
|
|
UUID $id, |
55
|
|
|
MIMEType $fileType, |
56
|
|
|
StringLiteral $description, |
57
|
|
|
StringLiteral $copyrightHolder, |
58
|
|
|
Url $sourceLocation, |
59
|
|
|
Language $language |
60
|
|
|
) { |
61
|
|
|
$this->mediaObjectId = $id; |
62
|
|
|
$this->mimeType = $fileType; |
63
|
|
|
$this->description = $description; |
|
|
|
|
64
|
|
|
$this->copyrightHolder = $copyrightHolder; |
|
|
|
|
65
|
|
|
$this->sourceLocation = $sourceLocation; |
66
|
|
|
$this->language = $language; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return Language |
71
|
|
|
*/ |
72
|
|
|
public function getLanguage() |
73
|
|
|
{ |
74
|
|
|
return $this->language; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return UUID |
79
|
|
|
*/ |
80
|
|
|
public function getMediaObjectId() |
81
|
|
|
{ |
82
|
|
|
return $this->mediaObjectId; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return StringLiteral |
87
|
|
|
*/ |
88
|
|
|
public function getDescription() |
89
|
|
|
{ |
90
|
|
|
return $this->description; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return StringLiteral |
95
|
|
|
*/ |
96
|
|
|
public function getCopyrightHolder() |
97
|
|
|
{ |
98
|
|
|
return $this->copyrightHolder; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return MIMEType |
103
|
|
|
*/ |
104
|
|
|
public function getMimeType() |
105
|
|
|
{ |
106
|
|
|
return $this->mimeType; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return Url |
111
|
|
|
*/ |
112
|
|
|
public function getSourceLocation() |
113
|
|
|
{ |
114
|
|
|
return $this->sourceLocation; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
|
|
public function serialize() |
121
|
|
|
{ |
122
|
|
|
return array( |
123
|
|
|
'media_object_id' => $this->getMediaObjectId()->toNative(), |
124
|
|
|
'mime_type' => $this->getMimeType()->toNative(), |
125
|
|
|
'description' => $this->getDescription()->toNative(), |
|
|
|
|
126
|
|
|
'copyright_holder' => $this->getCopyrightHolder()->toNative(), |
|
|
|
|
127
|
|
|
'source_location' => (string) $this->getSourceLocation(), |
128
|
|
|
'language' => (string) $this->getLanguage() |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param array $data |
134
|
|
|
* |
135
|
|
|
* @return MediaObjectCreated The object instance |
136
|
|
|
*/ |
137
|
|
View Code Duplication |
public static function deserialize(array $data) |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
return new static( |
140
|
|
|
new UUID($data['media_object_id']), |
141
|
|
|
new MIMEType($data['mime_type']), |
142
|
|
|
new StringLiteral($data['description']), |
143
|
|
|
new StringLiteral($data['copyright_holder']), |
144
|
|
|
Url::fromNative($data['source_location']), |
145
|
|
|
array_key_exists('language', $data) ? new Language($data['language']) : new Language('nl') |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
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.