1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DH\Adf\Node\Mark; |
6
|
|
|
|
7
|
|
|
use DH\Adf\Node\BlockNode; |
8
|
|
|
use DH\Adf\Node\MarkNode; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @see https://developer.atlassian.com/cloud/jira/platform/apis/document/marks/link |
12
|
|
|
*/ |
13
|
|
|
class Link extends MarkNode |
14
|
|
|
{ |
15
|
|
|
protected string $type = 'link'; |
16
|
|
|
private string $href; |
17
|
|
|
private ?string $title; |
18
|
|
|
private ?string $id; |
19
|
|
|
private ?string $collection; |
20
|
|
|
private ?string $occurrenceKey; |
21
|
|
|
|
22
|
|
|
public function __construct(string $href, ?string $title = null, ?string $id = null, ?string $collection = null, ?string $occurrenceKey = null) |
23
|
|
|
{ |
24
|
|
|
$this->href = $href; |
25
|
|
|
$this->title = $title; |
26
|
|
|
$this->id = $id; |
27
|
|
|
$this->collection = $collection; |
28
|
|
|
$this->occurrenceKey = $occurrenceKey; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function load(array $data, ?BlockNode $parent = null): self |
32
|
|
|
{ |
33
|
|
|
self::checkNodeData(static::class, $data); |
34
|
|
|
self::checkRequiredKeys(['href'], $data['attrs']); |
35
|
|
|
|
36
|
|
|
return new self( |
37
|
|
|
$data['attrs']['href'], |
38
|
|
|
$data['attrs']['title'] ?? null, |
39
|
|
|
$data['attrs']['id'] ?? null, |
40
|
|
|
$data['attrs']['collection'] ?? null, |
41
|
|
|
$data['attrs']['occurrenceKey'] ?? null, |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getType(): string |
46
|
|
|
{ |
47
|
|
|
return $this->type; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getHref(): string |
51
|
|
|
{ |
52
|
|
|
return $this->href; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getTitle(): ?string |
56
|
|
|
{ |
57
|
|
|
return $this->title; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getId(): ?string |
61
|
|
|
{ |
62
|
|
|
return $this->id; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getCollection(): ?string |
66
|
|
|
{ |
67
|
|
|
return $this->collection; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getOccurrenceKey(): ?string |
71
|
|
|
{ |
72
|
|
|
return $this->occurrenceKey; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function attrs(): array |
76
|
|
|
{ |
77
|
|
|
$attrs = [ |
78
|
|
|
'href' => $this->href, |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
if (null !== $this->title) { |
82
|
|
|
$attrs['title'] = $this->title; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (null !== $this->id) { |
86
|
|
|
$attrs['id'] = $this->id; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if (null !== $this->collection) { |
90
|
|
|
$attrs['collection'] = $this->collection; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if (null !== $this->occurrenceKey) { |
94
|
|
|
$attrs['occurrenceKey'] = $this->occurrenceKey; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $attrs; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|