|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: arthur |
|
5
|
|
|
* Date: 10.03.19 |
|
6
|
|
|
* Time: 18:30 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Foundation\Generator\Managers; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Illuminate\Support\Str; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class GeneratorManager |
|
16
|
|
|
* @package Foundation\Generator\Managers |
|
17
|
|
|
*/ |
|
18
|
|
|
class GeneratorManager |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $moduleName; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var bool |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $overwrite; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* GeneratorManager constructor. |
|
33
|
|
|
* @param string $module |
|
34
|
|
|
*/ |
|
35
|
26 |
|
protected function __construct(string $module, bool $overwrite = false) |
|
36
|
|
|
{ |
|
37
|
26 |
|
$this->moduleName = $module; |
|
38
|
26 |
|
$this->overwrite = $overwrite; |
|
39
|
26 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $moduleName |
|
43
|
|
|
* @return GeneratorManager |
|
44
|
|
|
*/ |
|
45
|
26 |
|
public static function module(string $moduleName, bool $overwrite = false) |
|
46
|
|
|
{ |
|
47
|
26 |
|
return new GeneratorManager($moduleName, $overwrite); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
26 |
|
protected function call(string $commandName, $options) |
|
51
|
|
|
{ |
|
52
|
26 |
|
\Artisan::call("larapi:make:$commandName", $this->alterOptions($options)); |
|
53
|
26 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param $options |
|
57
|
|
|
* @return mixed |
|
58
|
|
|
*/ |
|
59
|
26 |
|
protected function alterOptions($options) |
|
60
|
|
|
{ |
|
61
|
26 |
|
$options['module'] = Str::studly($this->moduleName); |
|
62
|
26 |
|
if ($this->overwrite) |
|
63
|
25 |
|
$options['--overwrite'] = null; |
|
64
|
26 |
|
return $options; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $migrationName |
|
69
|
|
|
* @param string $tableName |
|
70
|
|
|
* @param bool $mongo |
|
71
|
|
|
*/ |
|
72
|
4 |
|
public function createMigration(string $migrationName, string $tableName, bool $mongo = false) |
|
73
|
|
|
{ |
|
74
|
|
|
$options = [ |
|
75
|
4 |
|
"name" => $migrationName, |
|
76
|
4 |
|
"--table" => $tableName, |
|
77
|
4 |
|
"--mongo" => $mongo |
|
78
|
|
|
]; |
|
79
|
4 |
|
$this->call('migration', $options); |
|
80
|
4 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $controllerName |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function createController(string $controllerName) |
|
86
|
|
|
{ |
|
87
|
|
|
$options = [ |
|
88
|
2 |
|
"name" => $controllerName, |
|
89
|
|
|
]; |
|
90
|
2 |
|
$this->call('controller', $options); |
|
91
|
2 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param string $modelName |
|
95
|
|
|
*/ |
|
96
|
3 |
|
public function createAttribute(string $attributeName) |
|
97
|
|
|
{ |
|
98
|
|
|
$options = [ |
|
99
|
3 |
|
"name" => $attributeName, |
|
100
|
|
|
]; |
|
101
|
3 |
|
$this->call('attribute', $options); |
|
102
|
3 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param string $name |
|
106
|
|
|
*/ |
|
107
|
|
|
public function createGuard(string $name) |
|
108
|
|
|
{ |
|
109
|
|
|
$options = [ |
|
110
|
|
|
"name" => $name, |
|
111
|
|
|
]; |
|
112
|
|
|
$this->call('attribute', $options); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param string $name |
|
117
|
|
|
*/ |
|
118
|
3 |
|
public function createDto(string $name) |
|
119
|
|
|
{ |
|
120
|
|
|
$options = [ |
|
121
|
3 |
|
"name" => $name, |
|
122
|
|
|
]; |
|
123
|
3 |
|
$this->call('dto', $options); |
|
124
|
3 |
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param string $serviceName |
|
128
|
|
|
*/ |
|
129
|
2 |
|
public function createService(string $serviceName) |
|
130
|
|
|
{ |
|
131
|
|
|
$options = [ |
|
132
|
2 |
|
"name" => $serviceName, |
|
133
|
|
|
]; |
|
134
|
2 |
|
$this->call('service', $options); |
|
135
|
2 |
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param string $serviceName |
|
139
|
|
|
*/ |
|
140
|
2 |
|
public function createServiceContract(string $serviceContractName) |
|
141
|
|
|
{ |
|
142
|
|
|
$options = [ |
|
143
|
2 |
|
"name" => $serviceContractName, |
|
144
|
|
|
]; |
|
145
|
2 |
|
$this->call('service-contract', $options); |
|
146
|
2 |
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param string $policyName |
|
150
|
|
|
*/ |
|
151
|
2 |
|
public function createPolicy(string $policyName) |
|
152
|
|
|
{ |
|
153
|
|
|
$options = [ |
|
154
|
2 |
|
"name" => $policyName, |
|
155
|
|
|
]; |
|
156
|
2 |
|
$this->call('policy', $options); |
|
157
|
2 |
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param string $eventName |
|
161
|
|
|
*/ |
|
162
|
1 |
|
public function createEvent(string $eventName) |
|
163
|
|
|
{ |
|
164
|
|
|
$options = [ |
|
165
|
1 |
|
"name" => $eventName, |
|
166
|
|
|
]; |
|
167
|
1 |
|
$this->call('event', $options); |
|
168
|
1 |
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param string $notificationName |
|
172
|
|
|
*/ |
|
173
|
1 |
|
public function createNotification(string $notificationName) |
|
174
|
|
|
{ |
|
175
|
|
|
$options = [ |
|
176
|
1 |
|
"name" => $notificationName, |
|
177
|
|
|
]; |
|
178
|
1 |
|
$this->call('notification', $options); |
|
179
|
1 |
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param string $providerName |
|
183
|
|
|
*/ |
|
184
|
2 |
|
public function createServiceProvider(string $providerName) |
|
185
|
|
|
{ |
|
186
|
|
|
$options = [ |
|
187
|
2 |
|
"name" => $providerName, |
|
188
|
|
|
]; |
|
189
|
2 |
|
$this->call('provider', $options); |
|
190
|
2 |
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @param string $seederName |
|
194
|
|
|
*/ |
|
195
|
1 |
|
public function createSeeder(string $seederName) |
|
196
|
|
|
{ |
|
197
|
|
|
$options = [ |
|
198
|
1 |
|
"name" => $seederName, |
|
199
|
|
|
]; |
|
200
|
1 |
|
$this->call('seeder', $options); |
|
201
|
1 |
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @param string $middlewareName |
|
205
|
|
|
*/ |
|
206
|
2 |
|
public function createMiddleware(string $middlewareName) |
|
207
|
|
|
{ |
|
208
|
|
|
$options = [ |
|
209
|
2 |
|
"name" => $middlewareName, |
|
210
|
|
|
]; |
|
211
|
2 |
|
$this->call('middleware', $options); |
|
212
|
2 |
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @param string $requestName |
|
216
|
|
|
*/ |
|
217
|
2 |
|
public function createRequest(string $requestName) |
|
218
|
|
|
{ |
|
219
|
|
|
$options = [ |
|
220
|
2 |
|
"name" => $requestName, |
|
221
|
|
|
]; |
|
222
|
2 |
|
$this->call('request', $options); |
|
223
|
2 |
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* @param string $ruleName |
|
227
|
|
|
*/ |
|
228
|
1 |
|
public function createRule(string $ruleName) |
|
229
|
|
|
{ |
|
230
|
|
|
$options = [ |
|
231
|
1 |
|
"name" => $ruleName, |
|
232
|
|
|
]; |
|
233
|
1 |
|
$this->call('rule', $options); |
|
234
|
1 |
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @param string $exceptionName |
|
238
|
|
|
*/ |
|
239
|
|
|
public function createException(string $exceptionName) |
|
240
|
|
|
{ |
|
241
|
|
|
$options = [ |
|
242
|
|
|
"name" => $exceptionName, |
|
243
|
|
|
]; |
|
244
|
|
|
$this->call('exception', $options); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @param string $permissionName |
|
249
|
|
|
*/ |
|
250
|
1 |
|
public function createPermission(string $permissionName) |
|
251
|
|
|
{ |
|
252
|
|
|
$options = [ |
|
253
|
1 |
|
"name" => $permissionName, |
|
254
|
|
|
]; |
|
255
|
1 |
|
$this->call('permission', $options); |
|
256
|
1 |
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @param string $version |
|
260
|
|
|
*/ |
|
261
|
2 |
|
public function createRoute(string $version) |
|
262
|
|
|
{ |
|
263
|
|
|
$options = [ |
|
264
|
2 |
|
'--versioning' => $version |
|
265
|
|
|
]; |
|
266
|
2 |
|
$this->call('route', $options); |
|
267
|
2 |
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @param string $moduleName |
|
271
|
|
|
*/ |
|
272
|
2 |
|
public function createComposer() |
|
273
|
|
|
{ |
|
274
|
2 |
|
$this->call('composer', []); |
|
275
|
2 |
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* @param string $testName |
|
279
|
|
|
* @param string $type |
|
280
|
|
|
*/ |
|
281
|
2 |
|
public function createTest(string $testName, string $type) |
|
282
|
|
|
{ |
|
283
|
|
|
$options = [ |
|
284
|
2 |
|
"name" => $testName, |
|
285
|
2 |
|
"--type" => $type |
|
286
|
|
|
]; |
|
287
|
2 |
|
$this->call('test', $options); |
|
288
|
2 |
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* @param string $modelName |
|
292
|
|
|
*/ |
|
293
|
2 |
|
public function createFactory(string $modelName) |
|
294
|
|
|
{ |
|
295
|
|
|
$options = [ |
|
296
|
2 |
|
"--model" => $modelName, |
|
297
|
|
|
]; |
|
298
|
2 |
|
$this->call('factory', $options); |
|
299
|
2 |
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* @param string $transformerName |
|
303
|
|
|
* @param string $modelName |
|
304
|
|
|
*/ |
|
305
|
1 |
|
public function createTransformer(string $transformerName, string $modelName) |
|
306
|
|
|
{ |
|
307
|
|
|
$options = [ |
|
308
|
1 |
|
"name" => $transformerName, |
|
309
|
1 |
|
"--model" => $modelName, |
|
310
|
|
|
]; |
|
311
|
1 |
|
$this->call('transformer', $options); |
|
312
|
1 |
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @param string $listenerName |
|
316
|
|
|
* @param string $eventName |
|
317
|
|
|
* @param bool $queued |
|
318
|
|
|
*/ |
|
319
|
3 |
|
public function createListener(string $listenerName, string $eventName, bool $queued = false) |
|
320
|
|
|
{ |
|
321
|
|
|
$options = [ |
|
322
|
3 |
|
"name" => $listenerName, |
|
323
|
3 |
|
"--event" => $eventName, |
|
324
|
3 |
|
"--queued" => $queued |
|
325
|
|
|
]; |
|
326
|
3 |
|
$this->call('listener', $options); |
|
327
|
3 |
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* @param string $jobName |
|
331
|
|
|
* @param bool $sync |
|
332
|
|
|
*/ |
|
333
|
2 |
|
public function createJob(string $jobName, bool $sync = false) |
|
334
|
|
|
{ |
|
335
|
|
|
$options = [ |
|
336
|
2 |
|
"name" => $jobName, |
|
337
|
2 |
|
"--sync" => $sync |
|
338
|
|
|
]; |
|
339
|
2 |
|
$this->call('job', $options); |
|
340
|
2 |
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* @param string $jobName |
|
344
|
|
|
* @param string|null $commandName |
|
345
|
|
|
*/ |
|
346
|
2 |
|
public function createCommand(string $name, ?string $commandName = null) |
|
347
|
|
|
{ |
|
348
|
|
|
$options = [ |
|
349
|
2 |
|
"name" => $name, |
|
350
|
2 |
|
"--command" => $commandName |
|
351
|
|
|
]; |
|
352
|
2 |
|
$this->call('command', $options); |
|
353
|
2 |
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* @param string $modelName |
|
357
|
|
|
* @param bool $mongo |
|
358
|
|
|
* @param bool $migration |
|
359
|
|
|
*/ |
|
360
|
2 |
|
public function createModel(string $modelName, ?bool $mongo = false, ?bool $migration = true) |
|
361
|
|
|
{ |
|
362
|
|
|
$options = [ |
|
363
|
2 |
|
"name" => $modelName, |
|
364
|
2 |
|
"--mongo" => $mongo, |
|
365
|
2 |
|
"--migration" => $migration |
|
366
|
|
|
]; |
|
367
|
2 |
|
$this->call('model', $options); |
|
368
|
2 |
|
} |
|
369
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
} |
|
372
|
|
|
|