|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace CloudPlayDev\ConfluenceClient\Entity; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use CloudPlayDev\ConfluenceClient\Api\Content; |
|
8
|
|
|
|
|
9
|
|
|
abstract class AbstractContent |
|
10
|
|
|
{ |
|
11
|
|
|
private ?int $id = null; |
|
12
|
|
|
private ?string $title = null; |
|
13
|
|
|
private ?string $space = null; |
|
14
|
|
|
|
|
15
|
|
|
private ?string $content = null; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var int[] |
|
19
|
|
|
*/ |
|
20
|
|
|
private array $ancestors = []; |
|
21
|
|
|
|
|
22
|
|
|
private int $version = 1; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var array<string, string> $children |
|
25
|
|
|
*/ |
|
26
|
|
|
private array $children = []; |
|
27
|
|
|
private ?string $url = null; |
|
28
|
|
|
protected string $type = Content::CONTENT_TYPE_GLOBAL; |
|
29
|
|
|
|
|
30
|
|
|
private ?int $containerId = null; |
|
31
|
|
|
private string $containerType = Content::CONTENT_TYPE_PAGE; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getType(): string |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->type; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $type |
|
43
|
|
|
* @return self |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setType(string $type): self |
|
46
|
|
|
{ |
|
47
|
|
|
$this->type = $type; |
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return int|null |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getId(): ?int |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->id; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param int $id |
|
61
|
|
|
* @return self |
|
62
|
|
|
*/ |
|
63
|
|
|
public function setId(int $id): self |
|
64
|
|
|
{ |
|
65
|
|
|
$this->id = $id; |
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getTitle(): ?string |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->title; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param string $title |
|
76
|
|
|
* @return self |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setTitle(string $title): self |
|
79
|
|
|
{ |
|
80
|
|
|
$this->title = $title; |
|
81
|
|
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return null|string |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getSpace(): ?string |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->space; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param string $space |
|
94
|
|
|
* @return self |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setSpace(string $space): self |
|
97
|
|
|
{ |
|
98
|
|
|
$this->space = $space; |
|
99
|
|
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return null|string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getContent(): ?string |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->content; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param string $content |
|
112
|
|
|
* @return self |
|
113
|
|
|
*/ |
|
114
|
|
|
public function setContent(string $content): self |
|
115
|
|
|
{ |
|
116
|
|
|
$this->content = $content; |
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return int |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getVersion(): int |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->version; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param int $version |
|
130
|
|
|
* @return self |
|
131
|
|
|
*/ |
|
132
|
|
|
public function setVersion(int $version): self |
|
133
|
|
|
{ |
|
134
|
|
|
$this->version = $version; |
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return array<string, string> |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getChildren(): array |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->children; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param array<string, string> $children |
|
148
|
|
|
* @return self |
|
149
|
|
|
*/ |
|
150
|
|
|
public function setChildren(array $children): self |
|
151
|
|
|
{ |
|
152
|
|
|
$this->children = $children; |
|
153
|
|
|
return $this; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return null|string |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getUrl(): ?string |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->url; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param string $url |
|
166
|
|
|
* @return self |
|
167
|
|
|
*/ |
|
168
|
|
|
public function setUrl(string $url): self |
|
169
|
|
|
{ |
|
170
|
|
|
$this->url = $url; |
|
171
|
|
|
return $this; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @param string $comment |
|
176
|
|
|
* @return ContentComment |
|
177
|
|
|
*/ |
|
178
|
|
|
public function createComment(string $comment): ContentComment |
|
179
|
|
|
{ |
|
180
|
|
|
$contentComment = new ContentComment(); |
|
181
|
|
|
$contentComment->setContainerId($this->getId()); |
|
182
|
|
|
$contentComment->setContainerType($this->getType()); |
|
183
|
|
|
$contentComment->setContent($comment); |
|
184
|
|
|
$contentComment->setSpace($this->getSpace()); |
|
|
|
|
|
|
185
|
|
|
return $contentComment; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @param string $title |
|
190
|
|
|
* @param string $body |
|
191
|
|
|
* @return ContentPage |
|
192
|
|
|
*/ |
|
193
|
|
|
public function createSubpage(string $title, string $body): ContentPage |
|
194
|
|
|
{ |
|
195
|
|
|
$contentPage = new ContentPage(); |
|
196
|
|
|
$contentPage->addAncestor($this->id); |
|
|
|
|
|
|
197
|
|
|
$contentPage->setContent($body); |
|
198
|
|
|
$contentPage->setTitle($title); |
|
199
|
|
|
$contentPage->setSpace($this->getSpace()); |
|
|
|
|
|
|
200
|
|
|
return $contentPage; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @return int|null |
|
205
|
|
|
*/ |
|
206
|
|
|
public function getContainerId(): ?int |
|
207
|
|
|
{ |
|
208
|
|
|
return $this->containerId; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @param int|null $containerId |
|
213
|
|
|
*/ |
|
214
|
|
|
public function setContainerId(?int $containerId): void |
|
215
|
|
|
{ |
|
216
|
|
|
$this->containerId = $containerId; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @return string |
|
221
|
|
|
*/ |
|
222
|
|
|
public function getContainerType(): string |
|
223
|
|
|
{ |
|
224
|
|
|
return $this->containerType; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @param string $containerType |
|
229
|
|
|
*/ |
|
230
|
|
|
public function setContainerType(string $containerType): void |
|
231
|
|
|
{ |
|
232
|
|
|
$this->containerType = $containerType; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @return int[] |
|
237
|
|
|
*/ |
|
238
|
|
|
public function getAncestors(): array |
|
239
|
|
|
{ |
|
240
|
|
|
return $this->ancestors; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* @param int[] $ancestors |
|
245
|
|
|
* @return self |
|
246
|
|
|
*/ |
|
247
|
|
|
public function setAncestors(array $ancestors): self |
|
248
|
|
|
{ |
|
249
|
|
|
$this->ancestors = $ancestors; |
|
250
|
|
|
return $this; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* @param int $id |
|
255
|
|
|
* @return self |
|
256
|
|
|
*/ |
|
257
|
|
|
public function addAncestor(int $id): self |
|
258
|
|
|
{ |
|
259
|
|
|
$this->ancestors[] = $id; |
|
260
|
|
|
return $this; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
} |
|
264
|
|
|
|