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