|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Media\Events; |
|
4
|
|
|
|
|
5
|
|
|
use Broadway\Serializer\SerializableInterface; |
|
6
|
|
|
use CultuurNet\UDB3\Media\Properties\MIMEType; |
|
7
|
|
|
use ValueObjects\Identity\UUID; |
|
8
|
|
|
use ValueObjects\String\String; |
|
9
|
|
|
|
|
10
|
|
|
class MediaObjectCreated implements SerializableInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var UUID |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $fileId; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var MIMEType |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $mimeType; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var String |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var String |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $copyrightHolder; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param UUID $fileId |
|
34
|
|
|
* @param MIMEType $fileType |
|
35
|
|
|
* @param String $description |
|
36
|
|
|
* @param String $copyrightHolder |
|
37
|
|
|
*/ |
|
38
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
39
|
|
|
UUID $fileId, |
|
40
|
|
|
MIMEType $fileType, |
|
41
|
|
|
String $description, |
|
42
|
|
|
String $copyrightHolder |
|
43
|
|
|
) { |
|
44
|
|
|
$this->fileId = $fileId; |
|
45
|
|
|
$this->mimeType = $fileType; |
|
46
|
|
|
$this->description = $description; |
|
|
|
|
|
|
47
|
|
|
$this->copyrightHolder = $copyrightHolder; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return UUID |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getFileId() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->fileId; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return String |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getDescription() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->description; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return String |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getCopyrightHolder() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->copyrightHolder; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return MIMEType |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getMimeType() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->mimeType; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
public function serialize() |
|
86
|
|
|
{ |
|
87
|
|
|
return array( |
|
88
|
|
|
'file_id' => $this->getFileId()->toNative(), |
|
89
|
|
|
'mime_type' => $this->getMimeType()->toNative(), |
|
90
|
|
|
'description' => $this->getDescription()->toNative(), |
|
91
|
|
|
'copyright_holder' => $this->getCopyrightHolder()->toNative(), |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return MediaObjectCreated The object instance |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function deserialize(array $data) |
|
99
|
|
|
{ |
|
100
|
|
|
return new static( |
|
101
|
|
|
new UUID($data['file_id']), |
|
102
|
|
|
new MIMEType($data['mime_type']), |
|
103
|
|
|
new String($data['description']), |
|
104
|
|
|
new String($data['copyright_holder']) |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
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.