|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DH\Adf\Node\Child; |
|
6
|
|
|
|
|
7
|
|
|
use DH\Adf\Node\BlockNode; |
|
8
|
|
|
use DH\Adf\Node\Node; |
|
9
|
|
|
use InvalidArgumentException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @see https://developer.atlassian.com/cloud/jira/platform/apis/document/nodes/media |
|
13
|
|
|
*/ |
|
14
|
|
|
class Media extends Node |
|
15
|
|
|
{ |
|
16
|
|
|
public const TYPE_FILE = 'file'; |
|
17
|
|
|
public const TYPE_LINK = 'link'; |
|
18
|
|
|
|
|
19
|
|
|
protected string $type = 'media'; |
|
20
|
|
|
private string $id; |
|
21
|
|
|
private string $mediaType; |
|
22
|
|
|
private string $collection; |
|
23
|
|
|
private ?string $occurrenceKey; |
|
24
|
|
|
private ?int $width; |
|
25
|
|
|
private ?int $height; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(string $id, string $mediaType, string $collection, ?int $width = null, ?int $height = null, ?string $occurrenceKey = null, ?BlockNode $parent = null) |
|
28
|
|
|
{ |
|
29
|
|
|
if (!\in_array($mediaType, [self::TYPE_FILE, self::TYPE_LINK], true)) { |
|
30
|
|
|
throw new InvalidArgumentException('Invalid media type'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
parent::__construct($parent); |
|
34
|
|
|
$this->id = $id; |
|
35
|
|
|
$this->mediaType = $mediaType; |
|
36
|
|
|
$this->collection = $collection; |
|
37
|
|
|
$this->occurrenceKey = $occurrenceKey; |
|
38
|
|
|
$this->width = $width; |
|
39
|
|
|
$this->height = $height; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function load(array $data, ?BlockNode $parent = null): self |
|
43
|
|
|
{ |
|
44
|
|
|
self::checkNodeData(static::class, $data, ['attrs']); |
|
45
|
|
|
self::checkRequiredKeys(['id', 'type', 'collection'], $data['attrs']); |
|
46
|
|
|
|
|
47
|
|
|
return new self( |
|
48
|
|
|
$data['attrs']['id'], |
|
49
|
|
|
$data['attrs']['type'], |
|
50
|
|
|
$data['attrs']['collection'], |
|
51
|
|
|
$data['attrs']['width'] ?? null, |
|
52
|
|
|
$data['attrs']['height'] ?? null, |
|
53
|
|
|
$data['attrs']['occurrenceKey'] ?? null, |
|
54
|
|
|
$parent |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function attrs(): array |
|
59
|
|
|
{ |
|
60
|
|
|
$attrs = parent::attrs(); |
|
61
|
|
|
|
|
62
|
|
|
$attrs['id'] = $this->id; |
|
63
|
|
|
$attrs['type'] = $this->mediaType; |
|
64
|
|
|
$attrs['collection'] = $this->collection; |
|
65
|
|
|
|
|
66
|
|
|
if (null !== $this->occurrenceKey) { |
|
67
|
|
|
$attrs['occurrenceKey'] = $this->occurrenceKey; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (null !== $this->width) { |
|
71
|
|
|
$attrs['width'] = $this->width; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (null !== $this->height) { |
|
75
|
|
|
$attrs['height'] = $this->height; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $attrs; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|