1: <?php
2: declare(strict_types=1);
3:
4: namespace om\ICal\Value;
5:
6: use om\ICal\Parameters;
7:
8: /**
9: * IMAGE of a calendar, event, task or journal entry (RFC 7986, section 5.10):
10: * a URI or inline binary data.
11: */
12: final readonly class Image {
13: /**
14: * @param ?string $uri the URI, null for inline data
15: * @param ?string $data the decoded data of VALUE=BINARY, null for a URI
16: */
17: public function __construct(
18: public ?string $uri,
19: public ?string $data,
20: public Parameters $parameters,
21: ) {
22: }
23:
24: public function isBinary(): bool {
25: return $this->data !== null;
26: }
27:
28: /**
29: * DISPLAY modes in upper case, e.g. BADGE (default), GRAPHIC, FULLSIZE, THUMBNAIL.
30: *
31: * @return list<string>
32: */
33: public function display(): array {
34: $display = array_map(strtoupper(...), $this->parameters->values('DISPLAY'));
35: return $display === [] ? ['BADGE'] : $display;
36: }
37:
38: /** Media type (FMTTYPE), e.g. image/png. */
39: public function mediaType(): ?string {
40: return $this->parameters->get('FMTTYPE');
41: }
42:
43: /** URI launched by a click on the image (ALTREP). */
44: public function altRep(): ?string {
45: return $this->parameters->get('ALTREP');
46: }
47: }
48: