1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SoliDry\Blocks; |
4
|
|
|
|
5
|
|
|
use SoliDry\ApiGenerator; |
6
|
|
|
use SoliDry\Controllers\BaseCommand; |
7
|
|
|
use SoliDry\Helpers\Classes; |
8
|
|
|
use SoliDry\Types\ApiInterface; |
9
|
|
|
use SoliDry\Types\DefaultInterface; |
10
|
|
|
use SoliDry\Types\DocumentationInterface; |
11
|
|
|
use SoliDry\Types\PhpInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Documentation |
15
|
|
|
* |
16
|
|
|
* @package SoliDry\Blocks |
17
|
|
|
* |
18
|
|
|
* @property BaseCommand generator |
19
|
|
|
*/ |
20
|
|
|
abstract class Documentation |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
use ContentManager; |
|
|
|
|
24
|
|
|
|
25
|
|
|
protected $generator; |
26
|
|
|
protected $sourceCode = ''; |
27
|
|
|
protected $className; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Controllers constructor. |
31
|
|
|
* |
32
|
|
|
* @param ApiGenerator $generator |
33
|
|
|
*/ |
34
|
|
|
public function __construct($generator) |
35
|
|
|
{ |
36
|
|
|
$this->generator = $generator; |
37
|
|
|
$this->className = Classes::getClassName($this->generator->objectName); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function setDefaultDocs() |
41
|
|
|
{ |
42
|
|
|
$this->setComment(DefaultInterface::METHOD_START); |
43
|
|
|
|
44
|
|
|
$this->openComment(); |
45
|
|
|
|
46
|
|
|
// generate basic info |
47
|
|
|
$this->setStarredComment(DocumentationInterface::OA_INFO . PhpInterface::OPEN_PARENTHESES); |
48
|
|
|
|
49
|
|
|
$this->setInfoParams(); |
50
|
|
|
|
51
|
|
|
// generate contact info |
52
|
|
|
$this->setContactInfo(); |
53
|
|
|
|
54
|
|
|
// generate license info |
55
|
|
|
$this->setLicenseInfo(); |
56
|
|
|
|
57
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES); |
58
|
|
|
|
59
|
|
|
$this->closeComment(); |
60
|
|
|
|
61
|
|
|
$this->setComment(DefaultInterface::METHOD_END); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Sets info params - title, version, description |
66
|
|
|
*/ |
67
|
|
|
private function setInfoParams(): void |
68
|
|
|
{ |
69
|
|
|
if (empty($this->generator->data[ApiInterface::API_INFO][ApiInterface::API_TITLE]) === false) { |
70
|
|
|
$this->setStarredComment('title="' . $this->generator->data[ApiInterface::API_INFO][ApiInterface::API_TITLE] . '",', |
71
|
|
|
1, 1); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (empty($this->generator->data[ApiInterface::API_INFO][ApiInterface::API_VERSION]) === false) { |
75
|
|
|
$this->setStarredComment('version="' . $this->generator->data[ApiInterface::API_INFO][ApiInterface::API_VERSION] . '",', |
76
|
|
|
1, 1); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (empty($this->generator->data[ApiInterface::API_INFO][ApiInterface::API_DESCRIPTION]) === false) { |
80
|
|
|
$this->setStarredComment('description="' . $this->generator->data[ApiInterface::API_INFO][ApiInterface::API_DESCRIPTION] . '",', |
81
|
|
|
1, 1); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Sets license info - name, url |
87
|
|
|
*/ |
88
|
|
|
private function setLicenseInfo(): void |
89
|
|
|
{ |
90
|
|
|
$this->setStarredComment(DocumentationInterface::OA_LICENSE . PhpInterface::OPEN_PARENTHESES, |
91
|
|
|
1, 1); |
92
|
|
|
|
93
|
|
|
if (empty($this->generator->data[ApiInterface::API_INFO][ApiInterface::API_LICENSE][ApiInterface::API_NAME]) === false) { |
94
|
|
|
$this->setStarredComment('name="' . $this->generator->data[ApiInterface::API_INFO][ApiInterface::API_LICENSE][ApiInterface::API_NAME] . '",', |
95
|
|
|
1, 2); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (empty($this->generator->data[ApiInterface::API_INFO][ApiInterface::API_LICENSE][ApiInterface::API_URL]) === false) { |
99
|
|
|
$this->setStarredComment('url="' . $this->generator->data[ApiInterface::API_INFO][ApiInterface::API_LICENSE][ApiInterface::API_URL] . '",', |
100
|
|
|
1, 2); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES . PhpInterface::COMMA, 1, 1); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Sets contact info - email, name, url |
108
|
|
|
*/ |
109
|
|
|
private function setContactInfo(): void |
110
|
|
|
{ |
111
|
|
|
$this->setStarredComment(DocumentationInterface::OA_CONTACT . PhpInterface::OPEN_PARENTHESES, |
112
|
|
|
1, 1); |
113
|
|
|
|
114
|
|
|
if (empty($this->generator->data[ApiInterface::API_INFO][ApiInterface::API_CONTACT][ApiInterface::API_EMAIL]) === false) { |
115
|
|
|
$this->setStarredComment('email="' . $this->generator->data[ApiInterface::API_INFO][ApiInterface::API_CONTACT][ApiInterface::API_EMAIL] . '",', |
116
|
|
|
1, 2); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if (empty($this->generator->data[ApiInterface::API_INFO][ApiInterface::API_CONTACT][ApiInterface::API_NAME]) === false) { |
120
|
|
|
$this->setStarredComment('name="' . $this->generator->data[ApiInterface::API_INFO][ApiInterface::API_CONTACT][ApiInterface::API_NAME] . '",', |
121
|
|
|
1, 2); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if (empty($this->generator->data[ApiInterface::API_INFO][ApiInterface::API_CONTACT][ApiInterface::API_URL]) === false) { |
125
|
|
|
$this->setStarredComment('url="' . $this->generator->data[ApiInterface::API_INFO][ApiInterface::API_CONTACT][ApiInterface::API_URL] . '",', |
126
|
|
|
1, 2); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES . PhpInterface::COMMA, 1, 1); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Sets doc comments for every controller |
134
|
|
|
*/ |
135
|
|
|
protected function setControllersDocs(): void |
136
|
|
|
{ |
137
|
|
|
$this->setComment(DefaultInterface::METHOD_START); |
138
|
|
|
|
139
|
|
|
$this->setIndex(); |
140
|
|
|
|
141
|
|
|
$this->setView(); |
142
|
|
|
|
143
|
|
|
$this->setCreate(); |
144
|
|
|
|
145
|
|
|
$this->setUpdate(); |
146
|
|
|
|
147
|
|
|
$this->setDelete(); |
148
|
|
|
|
149
|
|
|
$this->setComment(DefaultInterface::METHOD_END); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
private function setIndex(): void |
153
|
|
|
{ |
154
|
|
|
$this->openComment(); |
155
|
|
|
|
156
|
|
|
$this->setStarredComment(DocumentationInterface::OA_GET . PhpInterface::OPEN_PARENTHESES); |
157
|
|
|
|
158
|
|
|
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH |
159
|
|
|
. strtolower($this->generator->objectName) . '",', 1, 1); |
160
|
|
|
|
161
|
|
|
$this->setStarredComment('summary="Get ' . $this->generator->objectName . 's ",', 1, 1); |
162
|
|
|
|
163
|
|
|
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX |
164
|
|
|
. '"},', 1, 1); |
165
|
|
|
|
166
|
|
|
// define params |
167
|
|
|
$this->setParameter([ |
168
|
|
|
'in' => '"query"', |
169
|
|
|
'name' => '"include"', |
170
|
|
|
'required' => 'false', |
171
|
|
|
]); |
172
|
|
|
|
173
|
|
|
$this->setParameter([ |
174
|
|
|
'in' => '"query"', |
175
|
|
|
'name' => '"page"', |
176
|
|
|
'required' => 'false', |
177
|
|
|
]); |
178
|
|
|
|
179
|
|
|
$this->setParameter([ |
180
|
|
|
'in' => '"query"', |
181
|
|
|
'name' => '"limit"', |
182
|
|
|
'required' => 'false', |
183
|
|
|
]); |
184
|
|
|
|
185
|
|
|
$this->setParameter([ |
186
|
|
|
'in' => '"query"', |
187
|
|
|
'name' => '"sort"', |
188
|
|
|
'required' => 'false', |
189
|
|
|
]); |
190
|
|
|
|
191
|
|
|
$this->setParameter([ |
192
|
|
|
'in' => '"query"', |
193
|
|
|
'name' => '"data"', |
194
|
|
|
'required' => 'false', |
195
|
|
|
]); |
196
|
|
|
|
197
|
|
|
$this->setParameter([ |
198
|
|
|
'in' => '"query"', |
199
|
|
|
'name' => '"filter"', |
200
|
|
|
'required' => 'false', |
201
|
|
|
]); |
202
|
|
|
|
203
|
|
|
$this->setParameter([ |
204
|
|
|
'in' => '"query"', |
205
|
|
|
'name' => '"order_by"', |
206
|
|
|
'required' => 'false', |
207
|
|
|
]); |
208
|
|
|
|
209
|
|
|
$this->setResponse([ |
210
|
|
|
'response' => '200', |
211
|
|
|
'description' => '""', |
212
|
|
|
]); |
213
|
|
|
|
214
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES); |
215
|
|
|
|
216
|
|
|
$this->closeComment(); |
217
|
|
|
$this->setNewLines(); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
private function setView(): void |
221
|
|
|
{ |
222
|
|
|
$this->openComment(); |
223
|
|
|
|
224
|
|
|
$this->setStarredComment(DocumentationInterface::OA_GET . PhpInterface::OPEN_PARENTHESES); |
225
|
|
|
|
226
|
|
|
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH |
227
|
|
|
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}",', 1, 1); |
228
|
|
|
|
229
|
|
|
$this->setStarredComment('summary="Get ' . $this->generator->objectName . '",', 1, 1); |
230
|
|
|
|
231
|
|
|
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX |
232
|
|
|
. '"},', 1, 1); |
233
|
|
|
|
234
|
|
|
$this->setParameter([ |
235
|
|
|
'in' => '"query"', |
236
|
|
|
'name' => '"include"', |
237
|
|
|
'required' => 'false', |
238
|
|
|
]); |
239
|
|
|
|
240
|
|
|
$this->setParameter([ |
241
|
|
|
'in' => '"query"', |
242
|
|
|
'name' => '"page"', |
243
|
|
|
'required' => 'false', |
244
|
|
|
]); |
245
|
|
|
|
246
|
|
|
$this->setResponse([ |
247
|
|
|
'response' => '200', |
248
|
|
|
'description' => '""', |
249
|
|
|
]); |
250
|
|
|
|
251
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES); |
252
|
|
|
|
253
|
|
|
$this->closeComment(); |
254
|
|
|
$this->setNewLines(); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
private function setCreate(): void |
258
|
|
|
{ |
259
|
|
|
$this->openComment(); |
260
|
|
|
|
261
|
|
|
$this->setStarredComment(DocumentationInterface::OA_POST . PhpInterface::OPEN_PARENTHESES); |
262
|
|
|
|
263
|
|
|
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH |
264
|
|
|
. strtolower($this->generator->objectName) . '",', 1, 1); |
265
|
|
|
|
266
|
|
|
$this->setStarredComment('summary="Create ' . $this->generator->objectName . '",', 1, 1); |
267
|
|
|
|
268
|
|
|
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX |
269
|
|
|
. '"},', 1, 1); |
270
|
|
|
|
271
|
|
|
$this->setResponse([ |
272
|
|
|
'response' => '200', |
273
|
|
|
'description' => '""', |
274
|
|
|
]); |
275
|
|
|
|
276
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES); |
277
|
|
|
|
278
|
|
|
$this->closeComment(); |
279
|
|
|
$this->setNewLines(); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
private function setUpdate(): void |
283
|
|
|
{ |
284
|
|
|
$this->openComment(); |
285
|
|
|
|
286
|
|
|
$this->setStarredComment(DocumentationInterface::OA_PATCH . PhpInterface::OPEN_PARENTHESES); |
287
|
|
|
|
288
|
|
|
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH |
289
|
|
|
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}",', 1, 1); |
290
|
|
|
|
291
|
|
|
$this->setStarredComment('summary="Update ' . $this->generator->objectName . '",', 1, 1); |
292
|
|
|
|
293
|
|
|
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX |
294
|
|
|
. '"},', 1, 1); |
295
|
|
|
|
296
|
|
|
$this->setResponse([ |
297
|
|
|
'response' => '200', |
298
|
|
|
'description' => '""', |
299
|
|
|
]); |
300
|
|
|
|
301
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES); |
302
|
|
|
|
303
|
|
|
$this->closeComment(); |
304
|
|
|
$this->setNewLines(); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
private function setDelete(): void |
308
|
|
|
{ |
309
|
|
|
$this->openComment(); |
310
|
|
|
|
311
|
|
|
$this->setStarredComment(DocumentationInterface::OA_DELETE . PhpInterface::OPEN_PARENTHESES); |
312
|
|
|
|
313
|
|
|
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH |
314
|
|
|
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}",', 1, 1); |
315
|
|
|
|
316
|
|
|
$this->setStarredComment('summary="Delete ' . $this->generator->objectName . '",', 1, 1); |
317
|
|
|
|
318
|
|
|
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX |
319
|
|
|
. '"},', 1, 1); |
320
|
|
|
|
321
|
|
|
$this->setResponse([ |
322
|
|
|
'response' => '200', |
323
|
|
|
'description' => '""', |
324
|
|
|
]); |
325
|
|
|
|
326
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES); |
327
|
|
|
|
328
|
|
|
$this->closeComment(); |
329
|
|
|
$this->setNewLines(); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @param array $paramValues |
334
|
|
|
*/ |
335
|
|
|
private function setParameter(array $paramValues): void |
336
|
|
|
{ |
337
|
|
|
$this->setStarredComment(DocumentationInterface::OA_PARAMETER . PhpInterface::OPEN_PARENTHESES, 1, 1); |
338
|
|
|
foreach ($paramValues as $key => $val) { |
339
|
|
|
$this->setStarredComment($key . '=' . $val . ',', 1, 2); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES . PhpInterface::COMMA, 1, 1); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @param array $paramValues |
347
|
|
|
*/ |
348
|
|
|
private function setResponse(array $paramValues): void |
349
|
|
|
{ |
350
|
|
|
$this->setStarredComment(DocumentationInterface::OA_RESPONSE . PhpInterface::OPEN_PARENTHESES, 1, 1); |
351
|
|
|
foreach ($paramValues as $key => $val) { |
352
|
|
|
$this->setStarredComment($key . '=' . $val . ',', 1, 2); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES . PhpInterface::COMMA, 1, 1); |
356
|
|
|
} |
357
|
|
|
} |