|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace CloudPlayDev\ConfluenceClient\Entity; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Webmozart\Assert\Assert; |
|
8
|
|
|
use function in_array; |
|
9
|
|
|
|
|
10
|
|
|
class ContentBody implements Hydratable |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* confluence representation (markup html) |
|
14
|
|
|
*/ |
|
15
|
|
|
public const REPRESENTATION_STORAGE = 'storage'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* confluence representation (markup) |
|
19
|
|
|
*/ |
|
20
|
|
|
public const REPRESENTATION_EDITOR = 'editor'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* confluence representation (xhtml) |
|
24
|
|
|
*/ |
|
25
|
|
|
public const REPRESENTATION_VIEW = 'view'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* confluence representation |
|
29
|
|
|
*/ |
|
30
|
|
|
public const REPRESENTATION_EXPORT_VIEW = 'export_view'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* confluence representation |
|
34
|
|
|
*/ |
|
35
|
|
|
public const REPRESENTATION_STYLED_VIEW = 'styled_view'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* confluence representation (wiki markup) |
|
39
|
|
|
*/ |
|
40
|
|
|
public const REPRESENTATION_WIKI = 'wiki'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @example <ac:link><ri:user ri:userkey="a-valid-account-id" /></ac:link> |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
private string $value = ''; |
|
47
|
|
|
private string $representation = self::REPRESENTATION_STORAGE; |
|
48
|
|
|
|
|
49
|
|
|
public static function load(array $data): Hydratable |
|
50
|
|
|
{ |
|
51
|
|
|
$contentBody = new self; |
|
52
|
|
|
Assert::keyExists($data, 'value'); |
|
53
|
|
|
Assert::keyExists($data, 'representation'); |
|
54
|
|
|
Assert::string($data['value']); |
|
55
|
|
|
Assert::string($data['representation']); |
|
56
|
|
|
|
|
57
|
|
|
$contentBody->setValue($data['value']); |
|
58
|
|
|
$contentBody->setRepresentation($data['representation']); |
|
59
|
|
|
|
|
60
|
|
|
return $contentBody; |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function isSupported(string $representation): bool |
|
65
|
|
|
{ |
|
66
|
|
|
return (in_array($representation, [ |
|
67
|
|
|
self::REPRESENTATION_STORAGE, |
|
68
|
|
|
self::REPRESENTATION_EDITOR, |
|
69
|
|
|
self::REPRESENTATION_VIEW, |
|
70
|
|
|
self::REPRESENTATION_EXPORT_VIEW, |
|
71
|
|
|
self::REPRESENTATION_STYLED_VIEW, |
|
72
|
|
|
self::REPRESENTATION_WIKI, |
|
73
|
|
|
], true)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getValue(): string |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->value; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param string $value |
|
86
|
|
|
* @return self |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setValue(string $value): self |
|
89
|
|
|
{ |
|
90
|
|
|
$this->value = $value; |
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getRepresentation(): string |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->representation; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param string $representation |
|
104
|
|
|
* @return self |
|
105
|
|
|
*/ |
|
106
|
|
|
public function setRepresentation(string $representation): self |
|
107
|
|
|
{ |
|
108
|
|
|
$this->representation = $representation; |
|
109
|
|
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|