|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Library\Core\Models; |
|
4
|
|
|
|
|
5
|
|
|
abstract class AbstractWpConfigModelBuilder |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var string |
|
9
|
|
|
*/ |
|
10
|
|
|
public $name; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var array |
|
14
|
|
|
*/ |
|
15
|
|
|
public $args; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
public $labels; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
public $capabilities; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
public $rewrite; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
public $description; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get the value of name |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getName(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->name; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get the value of args |
|
49
|
|
|
* |
|
50
|
|
|
* @return mixed |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getArgs() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->args; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Set the value of args |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $args |
|
61
|
|
|
* |
|
62
|
|
|
* @return self |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setArgs(array $args) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->args = $args; |
|
67
|
|
|
|
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the value of labels |
|
73
|
|
|
* |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getLabels() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->labels; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* |
|
83
|
|
|
*/ |
|
84
|
|
|
public function setLabels(array $labels) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->labels = $labels + $this->getDefaultLabels( |
|
87
|
|
|
$labels['singular_name'], |
|
88
|
|
|
$labels['name'] |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get the value of rewrite |
|
96
|
|
|
* |
|
97
|
|
|
* @return array |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getRewrite(): array |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->rewrite; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Set the value of rewrite |
|
106
|
|
|
* |
|
107
|
|
|
* @param array $rewrite |
|
108
|
|
|
* |
|
109
|
|
|
* @return self |
|
110
|
|
|
*/ |
|
111
|
|
|
public function setRewrite(array $rewrite) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->rewrite = $rewrite; |
|
114
|
|
|
|
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Get the value of capabilities |
|
120
|
|
|
* |
|
121
|
|
|
* @return array |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getCapabilities(): array |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->capabilities; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Set the value of capabilities |
|
130
|
|
|
* |
|
131
|
|
|
* @param array $capabilities |
|
132
|
|
|
* |
|
133
|
|
|
* @return self |
|
134
|
|
|
*/ |
|
135
|
|
|
public function setCapabilities(array $capabilities) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->capabilities = $capabilities; |
|
138
|
|
|
|
|
139
|
|
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get the value of description |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getDescription(): string |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->description; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Set the value of description |
|
154
|
|
|
* |
|
155
|
|
|
* @param string $description |
|
156
|
|
|
* |
|
157
|
|
|
* @return self |
|
158
|
|
|
*/ |
|
159
|
|
|
public function setDescription(string $description) |
|
160
|
|
|
{ |
|
161
|
|
|
$this->description = $description; |
|
162
|
|
|
|
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* |
|
168
|
|
|
*/ |
|
169
|
|
|
public function hook() |
|
170
|
|
|
{ |
|
171
|
|
|
add_action('init', [$this, 'register']); |
|
172
|
|
|
|
|
173
|
|
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* |
|
178
|
|
|
*/ |
|
179
|
|
|
protected function buildArgs(array $args): array |
|
180
|
|
|
{ |
|
181
|
|
|
foreach ($this->getExaltedArgs() as $arg) { |
|
182
|
|
|
if (!empty($property = $this->{$arg})) { |
|
183
|
|
|
$args[$arg] = $property; |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
return $args; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* |
|
192
|
|
|
*/ |
|
193
|
|
|
public function getExaltedArgs() |
|
194
|
|
|
{ |
|
195
|
|
|
return ['labels', 'rewrite', 'capabilities', 'description']; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* |
|
200
|
|
|
*/ |
|
201
|
|
|
abstract protected function getDefaultLabels(string $single, string $plural): array; |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* |
|
205
|
|
|
*/ |
|
206
|
|
|
abstract public function register(); |
|
207
|
|
|
} |
|
208
|
|
|
|