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
|
|
|
final 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
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
45
|
|
|
UUID $id, |
46
|
|
|
MIMEType $fileType, |
47
|
|
|
StringLiteral $description, |
48
|
|
|
StringLiteral $copyrightHolder, |
49
|
|
|
Url $sourceLocation, |
50
|
|
|
Language $language |
51
|
|
|
) { |
52
|
|
|
$this->mediaObjectId = $id; |
53
|
|
|
$this->mimeType = $fileType; |
54
|
|
|
$this->description = $description; |
|
|
|
|
55
|
|
|
$this->copyrightHolder = $copyrightHolder; |
|
|
|
|
56
|
|
|
$this->sourceLocation = $sourceLocation; |
57
|
|
|
$this->language = $language; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getLanguage(): Language |
61
|
|
|
{ |
62
|
|
|
return $this->language; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getMediaObjectId(): UUID |
66
|
|
|
{ |
67
|
|
|
return $this->mediaObjectId; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getDescription(): StringLiteral |
71
|
|
|
{ |
72
|
|
|
return $this->description; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getCopyrightHolder(): StringLiteral |
76
|
|
|
{ |
77
|
|
|
return $this->copyrightHolder; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getMimeType(): MIMEType |
81
|
|
|
{ |
82
|
|
|
return $this->mimeType; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getSourceLocation(): Url |
86
|
|
|
{ |
87
|
|
|
return $this->sourceLocation; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function serialize(): array |
91
|
|
|
{ |
92
|
|
|
return array( |
93
|
|
|
'media_object_id' => $this->getMediaObjectId()->toNative(), |
94
|
|
|
'mime_type' => $this->getMimeType()->toNative(), |
95
|
|
|
'description' => $this->getDescription()->toNative(), |
96
|
|
|
'copyright_holder' => $this->getCopyrightHolder()->toNative(), |
97
|
|
|
'source_location' => (string) $this->getSourceLocation(), |
98
|
|
|
'language' => (string) $this->getLanguage(), |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
View Code Duplication |
public static function deserialize(array $data): MediaObjectCreated |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
return new self( |
105
|
|
|
new UUID($data['media_object_id']), |
106
|
|
|
new MIMEType($data['mime_type']), |
107
|
|
|
new StringLiteral($data['description']), |
108
|
|
|
new StringLiteral($data['copyright_holder']), |
109
|
|
|
Url::fromNative($data['source_location']), |
110
|
|
|
array_key_exists('language', $data) ? new Language($data['language']) : new Language('nl') |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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.