1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Iptc: A container class for IPTC data |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/PHPExif/php-exif-common for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2016 Tom Van Herreweghe <[email protected]> |
7
|
|
|
* @license http://github.com/PHPExif/php-exif-common/blob/master/LICENSE MIT License |
8
|
|
|
* @category PHPExif |
9
|
|
|
* @package Common |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PHPExif\Common\Data; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Iptc class |
16
|
|
|
* |
17
|
|
|
* Container for IPTC data |
18
|
|
|
* |
19
|
|
|
* @category PHPExif |
20
|
|
|
* @package Common |
21
|
|
|
*/ |
22
|
|
|
final class Iptc implements IptcInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $caption; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $copyright; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $credit; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $headline; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $jobtitle; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
private $keywords = array(); |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
private $source; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
private $title; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Contains the mapping of names to IPTC field numbers |
66
|
|
|
* |
67
|
|
|
* @var array |
68
|
|
|
*/ |
69
|
|
|
public static $iptcMapping = array( |
70
|
|
|
'caption' => '2#120', |
71
|
|
|
'copyright' => '2#116', |
72
|
|
|
'credit' => '2#110', |
73
|
|
|
'headline' => '2#105', |
74
|
|
|
'jobtitle' => '2#085', |
75
|
|
|
'keywords' => '2#025', |
76
|
|
|
'source' => '2#115', |
77
|
|
|
'title' => '2#005', |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param array $data |
82
|
|
|
*/ |
83
|
|
|
public function __construct(array $data = array()) |
84
|
|
|
{ |
85
|
|
|
foreach ($data as $key => $value) { |
86
|
|
|
if (!array_key_exists($key, self::$iptcMapping)) { |
87
|
|
|
continue; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->$key = $value; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritDoc} |
96
|
|
|
*/ |
97
|
|
|
public function toArray($withEmpty = true) |
98
|
|
|
{ |
99
|
|
|
$data = array(); |
100
|
|
|
$keys = array_keys(self::$iptcMapping); |
101
|
|
|
foreach ($keys as $prop) { |
102
|
|
|
$accessor = 'get' . ucfirst($prop); |
103
|
|
|
$value = $this->$accessor(); |
104
|
|
|
|
105
|
|
|
if (empty($value) && !$withEmpty) { |
106
|
|
|
continue; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$data[$prop] = $value; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $data; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritDoc} |
117
|
|
|
*/ |
118
|
|
|
public function getCaption() |
119
|
|
|
{ |
120
|
|
|
return $this->caption; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* {@inheritDoc} |
125
|
|
|
*/ |
126
|
|
|
public function withCaption($caption) |
127
|
|
|
{ |
128
|
|
|
$new = clone $this; |
129
|
|
|
$new->caption = $caption; |
130
|
|
|
|
131
|
|
|
return $new; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* {@inheritDoc} |
136
|
|
|
*/ |
137
|
|
|
public function getCopyright() |
138
|
|
|
{ |
139
|
|
|
return $this->copyright; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* {@inheritDoc} |
144
|
|
|
*/ |
145
|
|
|
public function withCopyright($copyright) |
146
|
|
|
{ |
147
|
|
|
$new = clone $this; |
148
|
|
|
$new->copyright = $copyright; |
149
|
|
|
|
150
|
|
|
return $new; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* {@inheritDoc} |
155
|
|
|
*/ |
156
|
|
|
public function getCredit() |
157
|
|
|
{ |
158
|
|
|
return $this->credit; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* {@inheritDoc} |
163
|
|
|
*/ |
164
|
|
|
public function withCredit($credit) |
165
|
|
|
{ |
166
|
|
|
$new = clone $this; |
167
|
|
|
$new->credit = $credit; |
168
|
|
|
|
169
|
|
|
return $new; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* {@inheritDoc} |
174
|
|
|
*/ |
175
|
|
|
public function getHeadline() |
176
|
|
|
{ |
177
|
|
|
return $this->headline; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* {@inheritDoc} |
182
|
|
|
*/ |
183
|
|
|
public function withHeadline($headline) |
184
|
|
|
{ |
185
|
|
|
$new = clone $this; |
186
|
|
|
$new->headline = $headline; |
187
|
|
|
|
188
|
|
|
return $new; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* {@inheritDoc} |
193
|
|
|
*/ |
194
|
|
|
public function getJobtitle() |
195
|
|
|
{ |
196
|
|
|
return $this->jobtitle; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* {@inheritDoc} |
201
|
|
|
*/ |
202
|
|
|
public function withJobtitle($jobtitle) |
203
|
|
|
{ |
204
|
|
|
$new = clone $this; |
205
|
|
|
$new->jobtitle = $jobtitle; |
206
|
|
|
|
207
|
|
|
return $new; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* {@inheritDoc} |
212
|
|
|
*/ |
213
|
|
|
public function getKeywords() |
214
|
|
|
{ |
215
|
|
|
return $this->keywords; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* {@inheritDoc} |
220
|
|
|
*/ |
221
|
|
|
public function withKeywords(array $keywords) |
222
|
|
|
{ |
223
|
|
|
$new = clone $this; |
224
|
|
|
$new->keywords = $keywords; |
225
|
|
|
|
226
|
|
|
return $new; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* {@inheritDoc} |
231
|
|
|
*/ |
232
|
|
|
public function getSource() |
233
|
|
|
{ |
234
|
|
|
return $this->source; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* {@inheritDoc} |
239
|
|
|
*/ |
240
|
|
|
public function withSource($source) |
241
|
|
|
{ |
242
|
|
|
$new = clone $this; |
243
|
|
|
$new->source = $source; |
244
|
|
|
|
245
|
|
|
return $new; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* {@inheritDoc} |
250
|
|
|
*/ |
251
|
|
|
public function getTitle() |
252
|
|
|
{ |
253
|
|
|
return $this->title; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* {@inheritDoc} |
258
|
|
|
*/ |
259
|
|
|
public function withTitle($title) |
260
|
|
|
{ |
261
|
|
|
$new = clone $this; |
262
|
|
|
$new->title = $title; |
263
|
|
|
|
264
|
|
|
return $new; |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|