|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PWWEB\Artomator\Common; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use InfyOm\Generator\Common\CommandData as Data; |
|
7
|
|
|
use InfyOm\Generator\Common\GeneratorConfig as Config; |
|
8
|
|
|
|
|
9
|
|
|
class GeneratorConfig extends Config |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Path GraphQL. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
public $pathGraphQL; |
|
17
|
|
|
/** |
|
18
|
|
|
* Path Contract. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
public $pathContract; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* GraphQL Name. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
public $gName; |
|
30
|
|
|
/** |
|
31
|
|
|
* GraphQL Plural. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
public $gPlural; |
|
36
|
|
|
/** |
|
37
|
|
|
* GraphQL Camel. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
public $gCamel; |
|
42
|
|
|
/** |
|
43
|
|
|
* GraphQL Camel Plural. |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
public $gCamelPlural; |
|
48
|
|
|
/** |
|
49
|
|
|
* GraphQL Snake. |
|
50
|
|
|
* |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
public $gSnake; |
|
54
|
|
|
/** |
|
55
|
|
|
* GraphQL Snake Plural. |
|
56
|
|
|
* |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
public $gSnakePlural; |
|
60
|
|
|
/** |
|
61
|
|
|
* GraphQL Dashed. |
|
62
|
|
|
* |
|
63
|
|
|
* @var string |
|
64
|
|
|
*/ |
|
65
|
|
|
public $gDashed; |
|
66
|
|
|
/** |
|
67
|
|
|
* GraphQL Dashed Plural. |
|
68
|
|
|
* |
|
69
|
|
|
* @var string |
|
70
|
|
|
*/ |
|
71
|
|
|
public $gDashedPlural; |
|
72
|
|
|
/** |
|
73
|
|
|
* GraphQL Slash. |
|
74
|
|
|
* |
|
75
|
|
|
* @var string |
|
76
|
|
|
*/ |
|
77
|
|
|
public $gSlash; |
|
78
|
|
|
/** |
|
79
|
|
|
* GraphQL Slash Plural. |
|
80
|
|
|
* |
|
81
|
|
|
* @var string |
|
82
|
|
|
*/ |
|
83
|
|
|
public $gSlashPlural; |
|
84
|
|
|
/** |
|
85
|
|
|
* GraphQL Human. |
|
86
|
|
|
* |
|
87
|
|
|
* @var string |
|
88
|
|
|
*/ |
|
89
|
|
|
public $gHuman; |
|
90
|
|
|
/** |
|
91
|
|
|
* GraphQL Human Plural. |
|
92
|
|
|
* |
|
93
|
|
|
* @var string |
|
94
|
|
|
*/ |
|
95
|
|
|
public $gHumanPlural; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* GraphQL Namespace Contract. |
|
99
|
|
|
* |
|
100
|
|
|
* @var string |
|
101
|
|
|
*/ |
|
102
|
|
|
public $nsContract; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Command Options. |
|
106
|
|
|
* |
|
107
|
|
|
* @var array |
|
108
|
|
|
*/ |
|
109
|
|
|
public static $availableOptions = [ |
|
110
|
|
|
'fieldsFile', |
|
111
|
|
|
'jsonFromGUI', |
|
112
|
|
|
'tableName', |
|
113
|
|
|
'fromTable', |
|
114
|
|
|
'ignoreFields', |
|
115
|
|
|
'save', |
|
116
|
|
|
'primary', |
|
117
|
|
|
'prefix', |
|
118
|
|
|
'paginate', |
|
119
|
|
|
'skip', |
|
120
|
|
|
'datatables', |
|
121
|
|
|
'views', |
|
122
|
|
|
'relations', |
|
123
|
|
|
'plural', |
|
124
|
|
|
'softDelete', |
|
125
|
|
|
'forceMigrate', |
|
126
|
|
|
'factory', |
|
127
|
|
|
'seeder', |
|
128
|
|
|
'repositoryPattern', |
|
129
|
|
|
'resources', |
|
130
|
|
|
'localized', |
|
131
|
|
|
'connection', |
|
132
|
|
|
'jqueryDT', |
|
133
|
|
|
'vue', |
|
134
|
|
|
]; |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Load Paths. |
|
138
|
|
|
* |
|
139
|
|
|
* @return void |
|
140
|
|
|
*/ |
|
141
|
|
|
public function loadPaths() |
|
142
|
|
|
{ |
|
143
|
|
|
parent::loadPaths(); |
|
144
|
|
|
|
|
145
|
|
|
$prefix = $this->prefixes['path']; |
|
146
|
|
|
|
|
147
|
|
|
if (false === empty($prefix)) { |
|
148
|
|
|
$prefix .= '/'; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
$viewPrefix = $this->prefixes['view']; |
|
152
|
|
|
|
|
153
|
|
|
if (false === empty($viewPrefix)) { |
|
154
|
|
|
$viewPrefix .= '/'; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
$this->pathFactory = $this->pathFactory.$prefix; |
|
158
|
|
|
|
|
159
|
|
|
$this->pathGraphQL = config('lighthouse.schema.register', base_path('graphql/schema.graphql')); |
|
160
|
|
|
|
|
161
|
|
|
$this->pathVues = config('pwweb.artomator.path.vues', resource_path('js/Pages/')).$viewPrefix.$this->mSnakePlural.'/'; |
|
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
$this->pathLocales = config('infyom.laravel_generator.path.models_locale_files', base_path('resources/lang/en/models/')).$prefix; |
|
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
$this->pathSchemas = config('infyom.laravel_generator.path.schema_files', resource_path('model_schemas/')).$prefix; |
|
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
$this->pathContract = config( |
|
168
|
|
|
'pwweb.artomator.path.contract', |
|
169
|
|
|
app_path('Contracts/') |
|
170
|
|
|
).$prefix; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Load Dynamic Variables. |
|
175
|
|
|
* |
|
176
|
|
|
* @param Data $commandData Command Data.\ |
|
177
|
|
|
* |
|
178
|
|
|
* @return Data |
|
179
|
|
|
*/ |
|
180
|
|
|
public function loadDynamicVariables(Data &$commandData) |
|
181
|
|
|
{ |
|
182
|
|
|
parent::loadDynamicVariables($commandData); |
|
183
|
|
|
$commandData->addDynamicVariable('$LICENSE_PACKAGE$', config('pwweb.artomator.license.package')); |
|
184
|
|
|
$commandData->addDynamicVariable('$LICENSE_AUTHORS$', license_authors(config('pwweb.artomator.license.authors'))); |
|
185
|
|
|
$commandData->addDynamicVariable('$LICENSE_COPYRIGHT$', config('pwweb.artomator.license.copyright')); |
|
186
|
|
|
$commandData->addDynamicVariable('$LICENSE$', config('pwweb.artomator.license.license')); |
|
187
|
|
|
$commandData->addDynamicVariable('$NAMESPACE_GRAPHQL_MODEL$', str_replace('\\', '\\\\', $this->nsModel)); |
|
188
|
|
|
|
|
189
|
|
|
$prefix = $this->prefixes['ns']; |
|
190
|
|
|
|
|
191
|
|
|
if (false === empty($prefix)) { |
|
192
|
|
|
$prefix = '\\'.$prefix; |
|
193
|
|
|
} |
|
194
|
|
|
$this->nsContract = config('pwweb.artomator.namespace.contract', 'App\Contracts').$prefix; |
|
195
|
|
|
$commandData->addDynamicVariable('$NAMESPACE_CONTRACT$', $this->nsContract); |
|
196
|
|
|
|
|
197
|
|
|
if (false === empty($this->prefixes['view'])) { |
|
198
|
|
|
$commandData->addDynamicVariable('$VUE_PREFIX$', $this->prefixes['view'].'/'); |
|
199
|
|
|
} else { |
|
200
|
|
|
$commandData->addDynamicVariable('$VUE_PREFIX$', ''); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
if (false === empty($this->prefixes['path'])) { |
|
204
|
|
|
$commandData->addDynamicVariable('$LANG_PREFIX$', Str::lower($this->prefixes['path'].'/')); |
|
205
|
|
|
} else { |
|
206
|
|
|
$commandData->addDynamicVariable('$LANG_PREFIX$', ''); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
return $commandData; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Prepare GraphQL Names. |
|
214
|
|
|
* |
|
215
|
|
|
* @param string|null $name Name. |
|
216
|
|
|
* |
|
217
|
|
|
* @return void |
|
218
|
|
|
*/ |
|
219
|
|
|
public function prepareGraphQLNames($name = null) |
|
220
|
|
|
{ |
|
221
|
|
|
if (true === is_null($name)) { |
|
222
|
|
|
$name = $this->mName; |
|
223
|
|
|
} |
|
224
|
|
|
$this->gName = $name; |
|
225
|
|
|
$this->gPlural = Str::plural($this->gName); |
|
226
|
|
|
$this->gCamel = Str::camel($this->gName); |
|
227
|
|
|
$this->gCamelPlural = Str::camel($this->gPlural); |
|
228
|
|
|
$this->gSnake = Str::snake($this->gName); |
|
229
|
|
|
$this->gSnakePlural = Str::snake($this->gPlural); |
|
230
|
|
|
$this->gDashed = str_replace('_', '-', Str::snake($this->gSnake)); |
|
231
|
|
|
$this->gDashedPlural = str_replace('_', '-', Str::snake($this->gSnakePlural)); |
|
232
|
|
|
$this->gSlash = str_replace('_', '/', Str::snake($this->gSnake)); |
|
233
|
|
|
$this->gSlashPlural = str_replace('_', '/', Str::snake($this->gSnakePlural)); |
|
234
|
|
|
$this->gHuman = Str::title(str_replace('_', ' ', Str::snake($this->gSnake))); |
|
235
|
|
|
$this->gHumanPlural = Str::title(str_replace('_', ' ', Str::snake($this->gSnakePlural))); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Load Dynamic GraphQL Variables. |
|
240
|
|
|
* |
|
241
|
|
|
* @param Data $commandData Command Data. |
|
242
|
|
|
* |
|
243
|
|
|
* @return Data |
|
244
|
|
|
*/ |
|
245
|
|
|
public function loadDynamicGraphQLVariables(Data &$commandData) |
|
246
|
|
|
{ |
|
247
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME$', $this->gName); |
|
248
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_CAMEL$', $this->gCamel); |
|
249
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL$', $this->gPlural); |
|
250
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_CAMEL$', $this->gCamelPlural); |
|
251
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_SNAKE$', $this->gSnake); |
|
252
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_SNAKE$', $this->gSnakePlural); |
|
253
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_DASHED$', $this->gDashed); |
|
254
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_DASHED$', $this->gDashedPlural); |
|
255
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_SLASH$', $this->gSlash); |
|
256
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_SLASH$', $this->gSlashPlural); |
|
257
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_HUMAN$', $this->gHuman); |
|
258
|
|
|
$commandData->addDynamicVariable('$GRAPHQL_NAME_PLURAL_HUMAN$', $this->gHumanPlural); |
|
259
|
|
|
|
|
260
|
|
|
return $commandData; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* Prepare Options. |
|
265
|
|
|
* |
|
266
|
|
|
* @param Data $commandData Command Data. |
|
267
|
|
|
* |
|
268
|
|
|
* @return void |
|
269
|
|
|
*/ |
|
270
|
|
|
public function prepareOptions(Data &$commandData) |
|
271
|
|
|
{ |
|
272
|
|
|
foreach (self::$availableOptions as $option) { |
|
273
|
|
|
$this->options[$option] = $commandData->commandObj->option($option); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
if (true === isset($options['fromTable']) && true === $this->options['fromTable']) { |
|
|
|
|
|
|
277
|
|
|
if (false === $this->options['tableName']) { |
|
278
|
|
|
$commandData->commandError('tableName required with fromTable option.'); |
|
279
|
|
|
exit; |
|
|
|
|
|
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
if (true === empty($this->options['save'])) { |
|
284
|
|
|
$this->options['save'] = config('infyom.laravel_generator.options.save_schema_file', true); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
if (true === empty($this->options['vue'])) { |
|
288
|
|
|
$this->options['vue'] = config('pwweb.artomator.options.vue_files', false); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
if (true === empty($this->options['localized'])) { |
|
292
|
|
|
$this->options['localized'] = config('infyom.laravel_generator.options.localized', false); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
if (true === $this->options['localized']) { |
|
296
|
|
|
$commandData->getTemplatesManager()->setUseLocale(true); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
$this->options['softDelete'] = config('infyom.laravel_generator.options.softDelete', false); |
|
300
|
|
|
$this->options['repositoryPattern'] = config('infyom.laravel_generator.options.repository_pattern', true); |
|
301
|
|
|
$this->options['resources'] = config('infyom.laravel_generator.options.resources', true); |
|
302
|
|
|
if (false === empty($this->options['skip'])) { |
|
303
|
|
|
$this->options['skip'] = array_map('trim', explode(',', $this->options['skip'])); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
if (false === empty($this->options['datatables'])) { |
|
307
|
|
|
if ('true' === strtolower($this->options['datatables'])) { |
|
308
|
|
|
$this->addOns['datatables'] = true; |
|
309
|
|
|
} else { |
|
310
|
|
|
$this->addOns['datatables'] = false; |
|
311
|
|
|
} |
|
312
|
|
|
} |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
|