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
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ServiceProviderGenerator |
12
|
|
|
* |
13
|
|
|
* @author Johannes Schobel <[email protected]> |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class ServiceProviderGenerator extends GeneratorCommand implements ComponentsGenerator |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command name. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $name = 'apiato:generate:serviceprovider'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The console command description. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $description = 'Create a ServiceProvider for a Container'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The type of class being generated. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $fileType = 'ServiceProvider'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The structure of the file path. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $pathStructure = '{container-name}/Providers/*'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The structure of the file name. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $nameStructure = '{file-name}'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The name of the stub file. |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
protected $stubName = 'providers/mainserviceprovider.stub'; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* User required/optional inputs expected to be passed while calling the command. |
62
|
|
|
* This is a replacement of the `getArguments` function "which reads whenever it's called". |
63
|
|
|
* |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
public $inputs = [ |
67
|
|
|
['stub', null, InputOption::VALUE_OPTIONAL, 'The stub file to load for this generator.'], |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function getUserInputs() |
74
|
|
|
{ |
75
|
|
|
$stub = Str::lower($this->checkParameterOrChoice( |
76
|
|
|
'stub', |
77
|
|
|
'Select the Stub you want to load', |
78
|
|
|
['Generic', 'MainServiceProvider'], |
79
|
|
|
0) |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
return [ |
83
|
|
|
'path-parameters' => [ |
84
|
|
|
'container-name' => $this->containerName, |
85
|
|
|
], |
86
|
|
|
'stub-parameters' => [ |
87
|
|
|
'_container-name' => Str::lower($this->containerName), |
88
|
|
|
'container-name' => $this->containerName, |
89
|
|
|
'class-name' => $this->fileName, |
90
|
|
|
], |
91
|
|
|
'file-parameters' => [ |
92
|
|
|
'file-name' => $this->fileName, |
93
|
|
|
], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get the default file name for this component to be generated |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getDefaultFileName() |
103
|
|
|
{ |
104
|
|
|
return 'MainServiceProvider'; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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.