1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Foundation\Generator\Commands; |
4
|
|
|
|
5
|
|
|
use Foundation\Core\Larapi; |
6
|
|
|
use Foundation\Generator\Abstracts\AbstractGeneratorCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
|
9
|
|
|
class TransformerMakeCommand extends AbstractGeneratorCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The console command name. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'larapi:make:transformer'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create a new transformer class for the specified module.'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The name of the generated resource. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $generatorName = 'transformer'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The stub name. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $stub = 'transformer.stub'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The file path. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $filePath = '/Transformers'; |
45
|
|
|
|
46
|
|
|
protected function getModelName(): string |
47
|
|
|
{ |
48
|
|
|
return once(function () { |
49
|
|
|
return $this->option('model') ?? $this->anticipate('For what model would you like to generate a transformer?', Larapi::getModule($this->getModuleName())->getModels()->getAllPhpFileNamesWithoutExtension(), $this->getModuleName()); |
50
|
|
|
}); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function stubOptions(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'CLASS' => $this->getClassName(), |
57
|
|
|
'NAMESPACE' => $this->getClassNamespace(), |
58
|
|
|
'MODEL' => $this->getModelName(), |
59
|
|
|
'MODEL_NAMESPACE' => $this->getModule()->getNamespace().'\\'.'Entities'.'\\'.$this->getModelName(), |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the console command options. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
protected function getOptions() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
['model', null, InputOption::VALUE_OPTIONAL, 'The Model name for the transformer.', null], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|