|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Library\System\Model\PostType; |
|
4
|
|
|
|
|
5
|
|
|
use Leonidas\Contracts\System\Model\PostType\PostTypeBuilderInterface; |
|
6
|
|
|
use Leonidas\Library\System\Model\AbstractSystemModelTypeBuilder; |
|
7
|
|
|
|
|
8
|
|
|
class PostTypeBuilder extends AbstractSystemModelTypeBuilder implements PostTypeBuilderInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected ?bool $excludeFromSearch; |
|
11
|
|
|
|
|
12
|
|
|
protected ?bool $showInAdminBar; |
|
13
|
|
|
|
|
14
|
|
|
protected ?bool $showInMenu; |
|
15
|
|
|
|
|
16
|
|
|
protected ?int $menuPosition; |
|
17
|
|
|
|
|
18
|
|
|
protected ?string $menuIcon; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var null|string|array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $capabilityType; |
|
24
|
|
|
|
|
25
|
|
|
protected ?bool $mapMetaCap; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var null|bool|array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $supports; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var null|callable |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $registerMetaBoxCb; |
|
36
|
|
|
|
|
37
|
|
|
protected ?array $taxonomies; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var null|bool|string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $archive; |
|
43
|
|
|
|
|
44
|
|
|
protected ?bool $canExport; |
|
45
|
|
|
|
|
46
|
|
|
protected ?bool $deleteWithUser; |
|
47
|
|
|
|
|
48
|
|
|
protected ?array $template; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var null|false|string |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $templateLock; |
|
54
|
|
|
|
|
55
|
|
|
public function name(string $name): self |
|
56
|
|
|
{ |
|
57
|
|
|
$this->name = $name; |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function plural(string $pluralLabel): self |
|
63
|
|
|
{ |
|
64
|
|
|
$this->pluralLabel = $pluralLabel; |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function singular(?string $singularLabel): self |
|
70
|
|
|
{ |
|
71
|
|
|
$this->singularLabel = $singularLabel; |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function description(?string $description): self |
|
77
|
|
|
{ |
|
78
|
|
|
$this->description = $description; |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function labels(?array $labels): self |
|
84
|
|
|
{ |
|
85
|
|
|
$this->labels = $labels; |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function public(?bool $isPublic): self |
|
91
|
|
|
{ |
|
92
|
|
|
$this->isPublic = $isPublic; |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function hierarchical(?bool $hierarchical): self |
|
98
|
|
|
{ |
|
99
|
|
|
$this->hierarchical = $hierarchical; |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function publiclyQueryable(?bool $publiclyQueryable): self |
|
105
|
|
|
{ |
|
106
|
|
|
$this->publiclyQueryable = $publiclyQueryable; |
|
107
|
|
|
|
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function showInUi(?bool $showInUi): self |
|
112
|
|
|
{ |
|
113
|
|
|
$this->isAllowedInUi = $showInUi; |
|
114
|
|
|
|
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function showInMenu($showInMenu): self |
|
119
|
|
|
{ |
|
120
|
|
|
$this->showInMenu = $showInMenu; |
|
121
|
|
|
|
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function showInNavMenus(?bool $showInNavMenu): self |
|
126
|
|
|
{ |
|
127
|
|
|
$this->displayedInMenu = $showInNavMenu; |
|
128
|
|
|
|
|
129
|
|
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function capabilities(?array $capabilities): self |
|
133
|
|
|
{ |
|
134
|
|
|
$this->capabilities = $capabilities; |
|
135
|
|
|
|
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function rewrite($rewrite): self |
|
140
|
|
|
{ |
|
141
|
|
|
$this->rewrite = $rewrite; |
|
142
|
|
|
|
|
143
|
|
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function queryVar($queryVar): self |
|
147
|
|
|
{ |
|
148
|
|
|
$this->queryVar = $queryVar; |
|
149
|
|
|
|
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function showInRest(?bool $showInRest): self |
|
154
|
|
|
{ |
|
155
|
|
|
$this->isAllowedInRest = $showInRest; |
|
156
|
|
|
|
|
157
|
|
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function restBase($restBase): self |
|
161
|
|
|
{ |
|
162
|
|
|
$this->restBase = $restBase; |
|
163
|
|
|
|
|
164
|
|
|
return $this; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function restNamespace($restNamespace): self |
|
168
|
|
|
{ |
|
169
|
|
|
$this->restNamespace = $restNamespace; |
|
170
|
|
|
|
|
171
|
|
|
return $this; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function restControllerClass($restControllerClass): self |
|
175
|
|
|
{ |
|
176
|
|
|
$this->restControllerClass = $restControllerClass; |
|
177
|
|
|
|
|
178
|
|
|
return $this; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function options(?array $extraArgs): self |
|
182
|
|
|
{ |
|
183
|
|
|
$this->options = $extraArgs; |
|
184
|
|
|
|
|
185
|
|
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function excludeFromSearch(?bool $excludeFromSearch): self |
|
189
|
|
|
{ |
|
190
|
|
|
$this->excludeFromSearch = $excludeFromSearch; |
|
191
|
|
|
|
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function showInAdminBar(?bool $showInAdminBar): self |
|
196
|
|
|
{ |
|
197
|
|
|
$this->showInAdminBar = $showInAdminBar; |
|
198
|
|
|
|
|
199
|
|
|
return $this; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function menuPosition(?int $menuPosition): self |
|
203
|
|
|
{ |
|
204
|
|
|
$this->menuPosition = $menuPosition; |
|
205
|
|
|
|
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function menuIcon(?string $menuIcon): self |
|
210
|
|
|
{ |
|
211
|
|
|
$this->menuIcon = $menuIcon; |
|
212
|
|
|
|
|
213
|
|
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
public function capabilityType($capabilityType): self |
|
217
|
|
|
{ |
|
218
|
|
|
$this->capabilityType = $capabilityType; |
|
219
|
|
|
|
|
220
|
|
|
return $this; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function mapMetaCap(?bool $mapMetaCap): self |
|
224
|
|
|
{ |
|
225
|
|
|
$this->mapMetaCap = $mapMetaCap; |
|
226
|
|
|
|
|
227
|
|
|
return $this; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
public function supports($supports): self |
|
231
|
|
|
{ |
|
232
|
|
|
$this->supports = $supports; |
|
233
|
|
|
|
|
234
|
|
|
return $this; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
public function registerMetaBoxCb(?callable $registerMetaBoxCb): self |
|
238
|
|
|
{ |
|
239
|
|
|
$this->registerMetaBoxCb = $registerMetaBoxCb; |
|
240
|
|
|
|
|
241
|
|
|
return $this; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
public function taxonomies(?array $taxonomies): self |
|
245
|
|
|
{ |
|
246
|
|
|
$this->taxonomies = $taxonomies; |
|
247
|
|
|
|
|
248
|
|
|
return $this; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
public function hasArchive($archive): self |
|
252
|
|
|
{ |
|
253
|
|
|
$this->archive = $archive; |
|
254
|
|
|
|
|
255
|
|
|
return $this; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
public function canExport(?bool $canExport): self |
|
259
|
|
|
{ |
|
260
|
|
|
$this->canExport = $canExport; |
|
261
|
|
|
|
|
262
|
|
|
return $this; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
public function deleteWithUser(?bool $deleteWithUser): self |
|
266
|
|
|
{ |
|
267
|
|
|
$this->deleteWithUser = $deleteWithUser; |
|
268
|
|
|
|
|
269
|
|
|
return $this; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
public function template(?array $template): self |
|
273
|
|
|
{ |
|
274
|
|
|
$this->template = $template; |
|
275
|
|
|
|
|
276
|
|
|
return $this; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
public function templateLock($templateLock): self |
|
280
|
|
|
{ |
|
281
|
|
|
$this->templateLock = $templateLock; |
|
282
|
|
|
|
|
283
|
|
|
return $this; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
public function get(): PostType |
|
287
|
|
|
{ |
|
288
|
|
|
return new PostType( |
|
289
|
|
|
$this->name, |
|
290
|
|
|
$this->pluralLabel, |
|
291
|
|
|
$this->singularLabel, |
|
292
|
|
|
$this->description ?? '', |
|
293
|
|
|
$this->labels ?? [], |
|
294
|
|
|
$this->isPublic ?? false, |
|
295
|
|
|
$this->hierarchical ?? false, |
|
296
|
|
|
$this->publiclyQueryable, |
|
297
|
|
|
$this->isAllowedInUi, |
|
298
|
|
|
$this->displayedInMenu, |
|
299
|
|
|
$this->isAllowedInNavMenus, |
|
300
|
|
|
$this->capabilities ?? [], |
|
301
|
|
|
$this->rewrite ?? true, |
|
302
|
|
|
$this->queryVar ?? true, |
|
303
|
|
|
$this->isAllowedInRest ?? false, |
|
304
|
|
|
$this->restBase ?? false, |
|
305
|
|
|
$this->restNamespace ?? false, |
|
306
|
|
|
$this->restControllerClass ?? false, |
|
307
|
|
|
$this->excludeFromSearch, |
|
308
|
|
|
$this->showInAdminBar, |
|
309
|
|
|
$this->menuPosition, |
|
310
|
|
|
$this->menuIcon, |
|
311
|
|
|
$this->capabilityType ?? 'post', |
|
312
|
|
|
$this->mapMetaCap ?? false, |
|
313
|
|
|
$this->supports ?? [], |
|
314
|
|
|
$this->registerMetaBoxCb, |
|
315
|
|
|
$this->taxonomies ?? [], |
|
316
|
|
|
$this->archive ?? false, |
|
317
|
|
|
$this->canExport ?? true, |
|
318
|
|
|
$this->deleteWithUser, |
|
319
|
|
|
$this->template ?? [], |
|
320
|
|
|
$this->templateLock ?? false, |
|
321
|
|
|
$this->options ?? [] |
|
322
|
|
|
); |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
public static function for(string $name): self |
|
326
|
|
|
{ |
|
327
|
|
|
return new self($name); |
|
328
|
|
|
} |
|
329
|
|
|
} |
|
330
|
|
|
|