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
|
|
|
protected function attrs(): array |
46
|
|
|
{ |
47
|
|
|
$attrs = [ |
48
|
|
|
'href' => $this->href, |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
if (null !== $this->title) { |
52
|
|
|
$attrs['title'] = $this->title; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (null !== $this->id) { |
56
|
|
|
$attrs['id'] = $this->id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (null !== $this->collection) { |
60
|
|
|
$attrs['collection'] = $this->collection; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (null !== $this->occurrenceKey) { |
64
|
|
|
$attrs['occurrenceKey'] = $this->occurrenceKey; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $attrs; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|