1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DH\Adf\Node\Inline; |
6
|
|
|
|
7
|
|
|
use DH\Adf\Node\InlineNode; |
8
|
|
|
use InvalidArgumentException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @see https://developer.atlassian.com/cloud/jira/platform/apis/document/nodes/text |
12
|
|
|
*/ |
13
|
|
|
class Status extends InlineNode |
14
|
|
|
{ |
15
|
|
|
public const COLOR_NEUTRAL = 'neutral'; |
16
|
|
|
public const COLOR_GREEN = 'green'; |
17
|
|
|
public const COLOR_PURPLE = 'purple'; |
18
|
|
|
public const COLOR_BLUE = 'blue'; |
19
|
|
|
public const COLOR_RED = 'red'; |
20
|
|
|
public const COLOR_YELLOW = 'yellow'; |
21
|
|
|
|
22
|
|
|
protected string $type = 'status'; |
23
|
|
|
private string $text; |
24
|
|
|
private string $color; |
25
|
|
|
private ?string $localId; |
26
|
|
|
private ?string $style; |
27
|
|
|
|
28
|
|
|
public function __construct(string $text, string $color, ?string $localId = null, ?string $style = null) |
29
|
|
|
{ |
30
|
|
|
if (!\in_array($color, [ |
31
|
|
|
self::COLOR_NEUTRAL, |
32
|
|
|
self::COLOR_GREEN, |
33
|
|
|
self::COLOR_PURPLE, |
34
|
|
|
self::COLOR_BLUE, |
35
|
|
|
self::COLOR_RED, |
36
|
|
|
self::COLOR_YELLOW, |
37
|
|
|
], true)) { |
38
|
|
|
throw new InvalidArgumentException('Invalid color'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->text = $text; |
42
|
|
|
$this->color = $color; |
43
|
|
|
$this->localId = $localId; |
44
|
|
|
$this->style = $style; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function load(array $data): self |
48
|
|
|
{ |
49
|
|
|
self::checkNodeData(static::class, $data, ['attrs']); |
50
|
|
|
self::checkRequiredKeys(['text', 'color'], $data['attrs']); |
51
|
|
|
|
52
|
|
|
return new self( |
53
|
|
|
$data['attrs']['text'], |
54
|
|
|
$data['attrs']['color'], |
55
|
|
|
$data['attrs']['localId'] ?? null, |
56
|
|
|
$data['attrs']['style'] ?? null |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function attrs(): array |
61
|
|
|
{ |
62
|
|
|
$attrs = parent::attrs(); |
63
|
|
|
$attrs['text'] = $this->text; |
64
|
|
|
$attrs['color'] = $this->color; |
65
|
|
|
|
66
|
|
|
if (null !== $this->localId) { |
67
|
|
|
$attrs['localId'] = $this->localId; |
68
|
|
|
} |
69
|
|
|
if (null !== $this->style) { |
70
|
|
|
$attrs['style'] = $this->style; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $attrs; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|