|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Media; |
|
4
|
|
|
|
|
5
|
|
|
use Broadway\EventSourcing\EventSourcedAggregateRoot; |
|
6
|
|
|
use Broadway\Serializer\SerializableInterface; |
|
7
|
|
|
use CultuurNet\UDB3\JsonLdSerializableInterface; |
|
8
|
|
|
use CultuurNet\UDB3\Media\Events\MediaObjectCreated; |
|
9
|
|
|
use CultuurNet\UDB3\Media\Properties\MIMEType; |
|
10
|
|
|
use ValueObjects\Identity\UUID; |
|
11
|
|
|
use ValueObjects\String\String; |
|
12
|
|
|
use ValueObjects\Web\Url; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* MediaObjects for UDB3. |
|
16
|
|
|
*/ |
|
17
|
|
|
class MediaObject extends EventSourcedAggregateRoot implements SerializableInterface, JsonLdSerializableInterface |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Mime type of the media object. |
|
22
|
|
|
* |
|
23
|
|
|
* @var MIMEType |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $mimeType; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* File id. |
|
29
|
|
|
* |
|
30
|
|
|
* @var UUID |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $fileId; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Url to the media object. |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $url; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Url to the thumbnail for the media object. |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $thumbnailUrl; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Description of the mediaobject. |
|
50
|
|
|
* |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $description; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Copyright info. |
|
57
|
|
|
* |
|
58
|
|
|
* @var string |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $copyrightHolder; |
|
61
|
|
|
|
|
62
|
|
|
public static function create(UUID $fileId, MIMEType $fileType, String $description, String $copyrightHolder) |
|
63
|
|
|
{ |
|
64
|
|
|
$mediaObject = new self(); |
|
65
|
|
|
$mediaObject->apply(new MediaObjectCreated($fileId, $fileType, $description, $copyrightHolder)); |
|
66
|
|
|
|
|
67
|
|
|
return $mediaObject; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getAggregateRootId() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->fileId; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function applyMediaObjectCreated(MediaObjectCreated $mediaObjectCreated) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->fileId = $mediaObjectCreated->getFileId(); |
|
81
|
|
|
$this->mimeType = $mediaObjectCreated->getMimeType(); |
|
82
|
|
|
$this->description = $mediaObjectCreated->getDescription(); |
|
|
|
|
|
|
83
|
|
|
$this->copyrightHolder = $mediaObjectCreated->getCopyrightHolder(); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getUrl() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->url; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getThumbnailUrl() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->thumbnailUrl; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getDescription() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->description; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getCopyrightHolder() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->copyrightHolder; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getFileId() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->fileId; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return MIMEType |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getMimeType() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->mimeType; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* {@inheritdoc} |
|
136
|
|
|
*/ |
|
137
|
|
|
public static function deserialize(array $data) |
|
138
|
|
|
{ |
|
139
|
|
|
return new static($data['url'], $data['mime_type'], $data['thumbnail_url'], $data['description'], $data['copyright_holder'], $data['file_id'], $type); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* {@inheritdoc} |
|
144
|
|
|
*/ |
|
145
|
|
|
public function serialize() |
|
146
|
|
|
{ |
|
147
|
|
|
return [ |
|
148
|
|
|
'mime_type' => $this->mimeType, |
|
149
|
|
|
'url' => (string) $this->url, |
|
150
|
|
|
'thumbnail_url' => (string) $this->thumbnailUrl, |
|
151
|
|
|
'description' => (string) $this->description, |
|
152
|
|
|
'copyright_holder' => (string) $this->copyrightHolder, |
|
153
|
|
|
'file_id' => (string) $this->fileId, |
|
154
|
|
|
]; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* {@inheritdoc} |
|
159
|
|
|
* TODO: This should probably be moved to a projector |
|
160
|
|
|
*/ |
|
161
|
|
|
public function toJsonLd() |
|
162
|
|
|
{ |
|
163
|
|
|
$jsonLd = [ |
|
164
|
|
|
// TODO: use an iri generator to generate a proper id |
|
165
|
|
|
'@id' => (string) $this->getFileId(), |
|
166
|
|
|
// TODO: base type off of MIME |
|
167
|
|
|
'@type' => 'schema:MediaObject', |
|
168
|
|
|
'contentUrl' => (string) $this->url, |
|
169
|
|
|
'thumbnailUrl' => (string) $this->thumbnailUrl, |
|
170
|
|
|
'description' => (string) $this->description, |
|
171
|
|
|
'copyrightHolder' => (string) $this->copyrightHolder, |
|
172
|
|
|
]; |
|
173
|
|
|
|
|
174
|
|
|
return $jsonLd; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function setUrl(Url $url) |
|
178
|
|
|
{ |
|
179
|
|
|
$this->url = $url; |
|
|
|
|
|
|
180
|
|
|
$this->thumbnailUrl = $url; |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..