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