1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apiato\Core\Generator\Commands; |
4
|
|
|
|
5
|
|
|
use Apiato\Core\Generator\GeneratorCommand; |
6
|
|
|
use Apiato\Core\Generator\Interfaces\ComponentsGenerator; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ConfigurationGenerator |
11
|
|
|
* |
12
|
|
|
* @author Johannes Schobel <[email protected]> |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
class ConfigurationGenerator extends GeneratorCommand implements ComponentsGenerator |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The console command name. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $name = 'apiato:generate:configuration'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The console command description. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Create a Configuration file for a Container'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The type of class being generated. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $fileType = 'Configuration'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The structure of the file path. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $pathStructure = '{container-name}/Configs/*'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The structure of the file name. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $nameStructure = '{file-name}-container'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The name of the stub file. |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $stubName = 'config.stub'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* User required/optional inputs expected to be passed while calling the command. |
61
|
|
|
* This is a replacement of the `getArguments` function "which reads whenever it's called". |
62
|
|
|
* |
63
|
|
|
* @var array |
64
|
|
|
*/ |
65
|
|
|
public $inputs = [ |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public function getUserInputs() |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
'path-parameters' => [ |
75
|
|
|
'container-name' => $this->containerName, |
76
|
|
|
], |
77
|
|
|
'stub-parameters' => [ |
78
|
|
|
'_container-name' => Str::lower($this->containerName), |
79
|
|
|
'container-name' => $this->containerName, |
80
|
|
|
'class-name' => $this->fileName, |
81
|
|
|
], |
82
|
|
|
'file-parameters' => [ |
83
|
|
|
'file-name' => $this->fileName, |
84
|
|
|
], |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the default file name for this component to be generated |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function getDefaultFileName() |
94
|
|
|
{ |
95
|
|
|
return Str::lower($this->containerName); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.