Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
79 / 79 |
|
100.00% |
30 / 30 |
CRAP | |
100.00% |
1 / 1 |
DocumentProperties | |
100.00% |
79 / 79 |
|
100.00% |
30 / 30 |
38 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
getCreator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setCreator | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLastModifiedBy | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setLastModifiedBy | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getCreated | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setCreated | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getModified | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setModified | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setTitle | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setDescription | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getSubject | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setSubject | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getKeywords | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setKeywords | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getCategory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setCategory | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getCompany | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setCompany | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getCustomProperties | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isCustomPropertySet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getCustomPropertyValue | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getCustomPropertyType | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setCustomProperty | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
5 | |||
getRevision | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setRevision | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setStatus | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
4 | * presentations documents. |
5 | * |
6 | * PHPPresentation is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPPresentation |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpPresentation; |
21 | |
22 | /** |
23 | * \PhpOffice\PhpPresentation\DocumentProperties. |
24 | */ |
25 | class DocumentProperties |
26 | { |
27 | public const PROPERTY_TYPE_BOOLEAN = 'b'; |
28 | public const PROPERTY_TYPE_INTEGER = 'i'; |
29 | public const PROPERTY_TYPE_FLOAT = 'f'; |
30 | public const PROPERTY_TYPE_DATE = 'd'; |
31 | public const PROPERTY_TYPE_STRING = 's'; |
32 | public const PROPERTY_TYPE_UNKNOWN = 'u'; |
33 | |
34 | /** |
35 | * Creator. |
36 | * |
37 | * @var string |
38 | */ |
39 | private $creator; |
40 | |
41 | /** |
42 | * LastModifiedBy. |
43 | * |
44 | * @var string |
45 | */ |
46 | private $lastModifiedBy; |
47 | |
48 | /** |
49 | * Created. |
50 | * |
51 | * @var int |
52 | */ |
53 | private $created; |
54 | |
55 | /** |
56 | * Modified. |
57 | * |
58 | * @var int |
59 | */ |
60 | private $modified; |
61 | |
62 | /** |
63 | * Title. |
64 | * |
65 | * @var string |
66 | */ |
67 | private $title; |
68 | |
69 | /** |
70 | * Description. |
71 | * |
72 | * @var string |
73 | */ |
74 | private $description; |
75 | |
76 | /** |
77 | * Subject. |
78 | * |
79 | * @var string |
80 | */ |
81 | private $subject; |
82 | |
83 | /** |
84 | * Keywords. |
85 | * |
86 | * @var string |
87 | */ |
88 | private $keywords; |
89 | |
90 | /** |
91 | * Category. |
92 | * |
93 | * @var string |
94 | */ |
95 | private $category; |
96 | |
97 | /** |
98 | * Company. |
99 | * |
100 | * @var string |
101 | */ |
102 | private $company; |
103 | |
104 | /** |
105 | * Revision. |
106 | * |
107 | * @var string |
108 | */ |
109 | private $revision; |
110 | |
111 | /** |
112 | * Status. |
113 | * |
114 | * @var string |
115 | */ |
116 | private $status; |
117 | |
118 | /** |
119 | * Custom Properties. |
120 | * |
121 | * @var array<string, array<string, mixed>> |
122 | */ |
123 | private $customProperties = []; |
124 | |
125 | /** |
126 | * Create a new \PhpOffice\PhpPresentation\DocumentProperties. |
127 | */ |
128 | public function __construct() |
129 | { |
130 | // Initialise values |
131 | $this->creator = 'Unknown Creator'; |
132 | $this->lastModifiedBy = $this->creator; |
133 | $this->created = time(); |
134 | $this->modified = time(); |
135 | $this->title = 'Untitled Presentation'; |
136 | $this->subject = ''; |
137 | $this->description = ''; |
138 | $this->keywords = ''; |
139 | $this->category = ''; |
140 | $this->company = 'Microsoft Corporation'; |
141 | $this->revision = ''; |
142 | $this->status = ''; |
143 | } |
144 | |
145 | /** |
146 | * Get Creator. |
147 | * |
148 | * @return string |
149 | */ |
150 | public function getCreator() |
151 | { |
152 | return $this->creator; |
153 | } |
154 | |
155 | /** |
156 | * Set Creator. |
157 | * |
158 | * @param string $pValue |
159 | * |
160 | * @return DocumentProperties |
161 | */ |
162 | public function setCreator($pValue = '') |
163 | { |
164 | $this->creator = $pValue; |
165 | |
166 | return $this; |
167 | } |
168 | |
169 | /** |
170 | * Get Last Modified By. |
171 | * |
172 | * @return string |
173 | */ |
174 | public function getLastModifiedBy() |
175 | { |
176 | return $this->lastModifiedBy; |
177 | } |
178 | |
179 | /** |
180 | * Set Last Modified By. |
181 | * |
182 | * @param string $pValue |
183 | * |
184 | * @return DocumentProperties |
185 | */ |
186 | public function setLastModifiedBy($pValue = '') |
187 | { |
188 | $this->lastModifiedBy = $pValue; |
189 | |
190 | return $this; |
191 | } |
192 | |
193 | /** |
194 | * Get Created. |
195 | * |
196 | * @return int |
197 | */ |
198 | public function getCreated() |
199 | { |
200 | return $this->created; |
201 | } |
202 | |
203 | /** |
204 | * Set Created. |
205 | * |
206 | * @param int $pValue |
207 | * |
208 | * @return DocumentProperties |
209 | */ |
210 | public function setCreated($pValue = null) |
211 | { |
212 | if (null === $pValue) { |
213 | $pValue = time(); |
214 | } |
215 | $this->created = $pValue; |
216 | |
217 | return $this; |
218 | } |
219 | |
220 | /** |
221 | * Get Modified. |
222 | * |
223 | * @return int |
224 | */ |
225 | public function getModified() |
226 | { |
227 | return $this->modified; |
228 | } |
229 | |
230 | /** |
231 | * Set Modified. |
232 | * |
233 | * @param int $pValue |
234 | * |
235 | * @return DocumentProperties |
236 | */ |
237 | public function setModified($pValue = null) |
238 | { |
239 | if (null === $pValue) { |
240 | $pValue = time(); |
241 | } |
242 | $this->modified = $pValue; |
243 | |
244 | return $this; |
245 | } |
246 | |
247 | /** |
248 | * Get Title. |
249 | * |
250 | * @return string |
251 | */ |
252 | public function getTitle() |
253 | { |
254 | return $this->title; |
255 | } |
256 | |
257 | /** |
258 | * Set Title. |
259 | * |
260 | * @param string $pValue |
261 | * |
262 | * @return DocumentProperties |
263 | */ |
264 | public function setTitle($pValue = '') |
265 | { |
266 | $this->title = $pValue; |
267 | |
268 | return $this; |
269 | } |
270 | |
271 | /** |
272 | * Get Description. |
273 | * |
274 | * @return string |
275 | */ |
276 | public function getDescription() |
277 | { |
278 | return $this->description; |
279 | } |
280 | |
281 | /** |
282 | * Set Description. |
283 | * |
284 | * @param string $pValue |
285 | * |
286 | * @return DocumentProperties |
287 | */ |
288 | public function setDescription($pValue = '') |
289 | { |
290 | $this->description = $pValue; |
291 | |
292 | return $this; |
293 | } |
294 | |
295 | /** |
296 | * Get Subject. |
297 | * |
298 | * @return string |
299 | */ |
300 | public function getSubject() |
301 | { |
302 | return $this->subject; |
303 | } |
304 | |
305 | /** |
306 | * Set Subject. |
307 | * |
308 | * @param string $pValue |
309 | * |
310 | * @return DocumentProperties |
311 | */ |
312 | public function setSubject($pValue = '') |
313 | { |
314 | $this->subject = $pValue; |
315 | |
316 | return $this; |
317 | } |
318 | |
319 | /** |
320 | * Get Keywords. |
321 | * |
322 | * @return string |
323 | */ |
324 | public function getKeywords() |
325 | { |
326 | return $this->keywords; |
327 | } |
328 | |
329 | /** |
330 | * Set Keywords. |
331 | * |
332 | * @param string $pValue |
333 | * |
334 | * @return DocumentProperties |
335 | */ |
336 | public function setKeywords($pValue = '') |
337 | { |
338 | $this->keywords = $pValue; |
339 | |
340 | return $this; |
341 | } |
342 | |
343 | /** |
344 | * Get Category. |
345 | * |
346 | * @return string |
347 | */ |
348 | public function getCategory() |
349 | { |
350 | return $this->category; |
351 | } |
352 | |
353 | /** |
354 | * Set Category. |
355 | * |
356 | * @param string $pValue |
357 | * |
358 | * @return DocumentProperties |
359 | */ |
360 | public function setCategory($pValue = '') |
361 | { |
362 | $this->category = $pValue; |
363 | |
364 | return $this; |
365 | } |
366 | |
367 | /** |
368 | * Get Company. |
369 | * |
370 | * @return string |
371 | */ |
372 | public function getCompany() |
373 | { |
374 | return $this->company; |
375 | } |
376 | |
377 | /** |
378 | * Set Company. |
379 | * |
380 | * @param string $pValue |
381 | * |
382 | * @return DocumentProperties |
383 | */ |
384 | public function setCompany($pValue = '') |
385 | { |
386 | $this->company = $pValue; |
387 | |
388 | return $this; |
389 | } |
390 | |
391 | /** |
392 | * Get a List of Custom Property Names. |
393 | * |
394 | * @return array<int, string> |
395 | */ |
396 | public function getCustomProperties(): array |
397 | { |
398 | return array_keys($this->customProperties); |
399 | } |
400 | |
401 | /** |
402 | * Check if a Custom Property is defined. |
403 | */ |
404 | public function isCustomPropertySet(string $propertyName): bool |
405 | { |
406 | return isset($this->customProperties[$propertyName]); |
407 | } |
408 | |
409 | /** |
410 | * Get a Custom Property Value. |
411 | * |
412 | * @return null|mixed |
413 | */ |
414 | public function getCustomPropertyValue(string $propertyName) |
415 | { |
416 | if ($this->isCustomPropertySet($propertyName)) { |
417 | return $this->customProperties[$propertyName]['value']; |
418 | } |
419 | |
420 | return null; |
421 | } |
422 | |
423 | /** |
424 | * Get a Custom Property Type. |
425 | */ |
426 | public function getCustomPropertyType(string $propertyName): ?string |
427 | { |
428 | if ($this->isCustomPropertySet($propertyName)) { |
429 | return $this->customProperties[$propertyName]['type']; |
430 | } |
431 | |
432 | return null; |
433 | } |
434 | |
435 | /** |
436 | * Set a Custom Property. |
437 | * |
438 | * @param mixed $propertyValue |
439 | * @param null|string $propertyType |
440 | * 'i' : Integer |
441 | * 'f' : Floating Point |
442 | * 's' : String |
443 | * 'd' : Date/Time |
444 | * 'b' : Boolean |
445 | */ |
446 | public function setCustomProperty(string $propertyName, $propertyValue = '', ?string $propertyType = null): self |
447 | { |
448 | if (!in_array($propertyType, [ |
449 | self::PROPERTY_TYPE_INTEGER, |
450 | self::PROPERTY_TYPE_FLOAT, |
451 | self::PROPERTY_TYPE_STRING, |
452 | self::PROPERTY_TYPE_DATE, |
453 | self::PROPERTY_TYPE_BOOLEAN, |
454 | ])) { |
455 | if (is_float($propertyValue)) { |
456 | $propertyType = self::PROPERTY_TYPE_FLOAT; |
457 | } elseif (is_int($propertyValue)) { |
458 | $propertyType = self::PROPERTY_TYPE_INTEGER; |
459 | } elseif (is_bool($propertyValue)) { |
460 | $propertyType = self::PROPERTY_TYPE_BOOLEAN; |
461 | } else { |
462 | $propertyType = self::PROPERTY_TYPE_STRING; |
463 | } |
464 | } |
465 | $this->customProperties[$propertyName] = [ |
466 | 'value' => $propertyValue, |
467 | 'type' => $propertyType, |
468 | ]; |
469 | |
470 | return $this; |
471 | } |
472 | |
473 | /** |
474 | * Get Revision. |
475 | */ |
476 | public function getRevision(): string |
477 | { |
478 | return $this->revision; |
479 | } |
480 | |
481 | /** |
482 | * Set Revision. |
483 | */ |
484 | public function setRevision(string $pValue = ''): self |
485 | { |
486 | $this->revision = $pValue; |
487 | |
488 | return $this; |
489 | } |
490 | |
491 | /** |
492 | * Get Status. |
493 | */ |
494 | public function getStatus(): string |
495 | { |
496 | return $this->status; |
497 | } |
498 | |
499 | /** |
500 | * Set Status. |
501 | */ |
502 | public function setStatus(string $pValue = ''): self |
503 | { |
504 | $this->status = $pValue; |
505 | |
506 | return $this; |
507 | } |
508 | } |