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
|
3 |
|
public function createDto(string $name) |
108
|
|
|
{ |
109
|
|
|
$options = [ |
110
|
3 |
|
"name" => $name, |
111
|
|
|
]; |
112
|
3 |
|
$this->call('dto', $options); |
113
|
3 |
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $serviceName |
117
|
|
|
*/ |
118
|
2 |
|
public function createService(string $serviceName) |
119
|
|
|
{ |
120
|
|
|
$options = [ |
121
|
2 |
|
"name" => $serviceName, |
122
|
|
|
]; |
123
|
2 |
|
$this->call('service', $options); |
124
|
2 |
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param string $serviceName |
128
|
|
|
*/ |
129
|
2 |
|
public function createServiceContract(string $serviceContractName) |
130
|
|
|
{ |
131
|
|
|
$options = [ |
132
|
2 |
|
"name" => $serviceContractName, |
133
|
|
|
]; |
134
|
2 |
|
$this->call('service-contract', $options); |
135
|
2 |
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param string $policyName |
139
|
|
|
*/ |
140
|
2 |
|
public function createPolicy(string $policyName) |
141
|
|
|
{ |
142
|
|
|
$options = [ |
143
|
2 |
|
"name" => $policyName, |
144
|
|
|
]; |
145
|
2 |
|
$this->call('policy', $options); |
146
|
2 |
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param string $eventName |
150
|
|
|
*/ |
151
|
1 |
|
public function createEvent(string $eventName) |
152
|
|
|
{ |
153
|
|
|
$options = [ |
154
|
1 |
|
"name" => $eventName, |
155
|
|
|
]; |
156
|
1 |
|
$this->call('event', $options); |
157
|
1 |
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param string $notificationName |
161
|
|
|
*/ |
162
|
1 |
|
public function createNotification(string $notificationName) |
163
|
|
|
{ |
164
|
|
|
$options = [ |
165
|
1 |
|
"name" => $notificationName, |
166
|
|
|
]; |
167
|
1 |
|
$this->call('notification', $options); |
168
|
1 |
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string $providerName |
172
|
|
|
*/ |
173
|
2 |
|
public function createServiceProvider(string $providerName) |
174
|
|
|
{ |
175
|
|
|
$options = [ |
176
|
2 |
|
"name" => $providerName, |
177
|
|
|
]; |
178
|
2 |
|
$this->call('provider', $options); |
179
|
2 |
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param string $seederName |
183
|
|
|
*/ |
184
|
1 |
|
public function createSeeder(string $seederName) |
185
|
|
|
{ |
186
|
|
|
$options = [ |
187
|
1 |
|
"name" => $seederName, |
188
|
|
|
]; |
189
|
1 |
|
$this->call('seeder', $options); |
190
|
1 |
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param string $middlewareName |
194
|
|
|
*/ |
195
|
2 |
|
public function createMiddleware(string $middlewareName) |
196
|
|
|
{ |
197
|
|
|
$options = [ |
198
|
2 |
|
"name" => $middlewareName, |
199
|
|
|
]; |
200
|
2 |
|
$this->call('middleware', $options); |
201
|
2 |
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param string $requestName |
205
|
|
|
*/ |
206
|
2 |
|
public function createRequest(string $requestName) |
207
|
|
|
{ |
208
|
|
|
$options = [ |
209
|
2 |
|
"name" => $requestName, |
210
|
|
|
]; |
211
|
2 |
|
$this->call('request', $options); |
212
|
2 |
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param string $ruleName |
216
|
|
|
*/ |
217
|
1 |
|
public function createRule(string $ruleName) |
218
|
|
|
{ |
219
|
|
|
$options = [ |
220
|
1 |
|
"name" => $ruleName, |
221
|
|
|
]; |
222
|
1 |
|
$this->call('rule', $options); |
223
|
1 |
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param string $exceptionName |
227
|
|
|
*/ |
228
|
|
|
public function createException(string $exceptionName) |
229
|
|
|
{ |
230
|
|
|
$options = [ |
231
|
|
|
"name" => $exceptionName, |
232
|
|
|
]; |
233
|
|
|
$this->call('exception', $options); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @param string $permissionName |
238
|
|
|
*/ |
239
|
1 |
|
public function createPermission(string $permissionName) |
240
|
|
|
{ |
241
|
|
|
$options = [ |
242
|
1 |
|
"name" => $permissionName, |
243
|
|
|
]; |
244
|
1 |
|
$this->call('permission', $options); |
245
|
1 |
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param string $version |
249
|
|
|
*/ |
250
|
2 |
|
public function createRoute(string $version) |
251
|
|
|
{ |
252
|
|
|
$options = [ |
253
|
2 |
|
'--versioning' => $version |
254
|
|
|
]; |
255
|
2 |
|
$this->call('route', $options); |
256
|
2 |
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param string $moduleName |
260
|
|
|
*/ |
261
|
2 |
|
public function createComposer() |
262
|
|
|
{ |
263
|
2 |
|
$this->call('composer', []); |
264
|
2 |
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param string $testName |
268
|
|
|
* @param string $type |
269
|
|
|
*/ |
270
|
2 |
|
public function createTest(string $testName, string $type) |
271
|
|
|
{ |
272
|
|
|
$options = [ |
273
|
2 |
|
"name" => $testName, |
274
|
2 |
|
"--type" => $type |
275
|
|
|
]; |
276
|
2 |
|
$this->call('test', $options); |
277
|
2 |
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @param string $modelName |
281
|
|
|
*/ |
282
|
2 |
|
public function createFactory(string $modelName) |
283
|
|
|
{ |
284
|
|
|
$options = [ |
285
|
2 |
|
"--model" => $modelName, |
286
|
|
|
]; |
287
|
2 |
|
$this->call('factory', $options); |
288
|
2 |
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param string $transformerName |
292
|
|
|
* @param string $modelName |
293
|
|
|
*/ |
294
|
1 |
|
public function createTransformer(string $transformerName, string $modelName) |
295
|
|
|
{ |
296
|
|
|
$options = [ |
297
|
1 |
|
"name" => $transformerName, |
298
|
1 |
|
"--model" => $modelName, |
299
|
|
|
]; |
300
|
1 |
|
$this->call('transformer', $options); |
301
|
1 |
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @param string $listenerName |
305
|
|
|
* @param string $eventName |
306
|
|
|
* @param bool $queued |
307
|
|
|
*/ |
308
|
3 |
|
public function createListener(string $listenerName, string $eventName, bool $queued = false) |
309
|
|
|
{ |
310
|
|
|
$options = [ |
311
|
3 |
|
"name" => $listenerName, |
312
|
3 |
|
"--event" => $eventName, |
313
|
3 |
|
"--queued" => $queued |
314
|
|
|
]; |
315
|
3 |
|
$this->call('listener', $options); |
316
|
3 |
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param string $jobName |
320
|
|
|
* @param bool $sync |
321
|
|
|
*/ |
322
|
2 |
|
public function createJob(string $jobName, bool $sync = false) |
323
|
|
|
{ |
324
|
|
|
$options = [ |
325
|
2 |
|
"name" => $jobName, |
326
|
2 |
|
"--sync" => $sync |
327
|
|
|
]; |
328
|
2 |
|
$this->call('job', $options); |
329
|
2 |
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @param string $jobName |
333
|
|
|
* @param string|null $commandName |
334
|
|
|
*/ |
335
|
2 |
|
public function createCommand(string $name, ?string $commandName = null) |
336
|
|
|
{ |
337
|
|
|
$options = [ |
338
|
2 |
|
"name" => $name, |
339
|
2 |
|
"--command" => $commandName |
340
|
|
|
]; |
341
|
2 |
|
$this->call('command', $options); |
342
|
2 |
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @param string $modelName |
346
|
|
|
* @param bool $mongo |
347
|
|
|
* @param bool $migration |
348
|
|
|
*/ |
349
|
2 |
|
public function createModel(string $modelName, ?bool $mongo = false, ?bool $migration = true) |
350
|
|
|
{ |
351
|
|
|
$options = [ |
352
|
2 |
|
"name" => $modelName, |
353
|
2 |
|
"--mongo" => $mongo, |
354
|
2 |
|
"--migration" => $migration |
355
|
|
|
]; |
356
|
2 |
|
$this->call('model', $options); |
357
|
2 |
|
} |
358
|
|
|
|
359
|
|
|
|
360
|
|
|
} |
361
|
|
|
|