1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Nwidart\Modules\Support\Stub; |
7
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
|
11
|
|
|
class ProviderMakeCommand extends GeneratorCommand |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
use ModuleCommandTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The name of argument name. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $argumentName = 'name'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The console command name. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $name = 'module:make-provider'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The console command description. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $description = 'Create a new service provider class for the specified module.'; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get default namespace. |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
57 |
|
public function getDefaultNamespace() |
44
|
|
|
{ |
45
|
57 |
|
return 'Providers'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the console command arguments. |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
60 |
|
protected function getArguments() |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
60 |
|
['name', InputArgument::REQUIRED, 'The service provider name.'], |
58
|
|
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the console command options. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
60 |
|
protected function getOptions() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
60 |
|
['master', null, InputOption::VALUE_NONE, 'Indicates the master service provider', null], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return mixed |
78
|
|
|
*/ |
79
|
57 |
|
protected function getTemplateContents() |
80
|
|
|
{ |
81
|
57 |
|
$stub = $this->option('master') ? 'scaffold/provider' : 'provider'; |
82
|
|
|
|
83
|
57 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
84
|
|
|
|
85
|
57 |
|
return (new Stub('/'.$stub.'.stub', [ |
86
|
57 |
|
'NAMESPACE' => $this->getClassNamespace($module), |
87
|
57 |
|
'CLASS' => $this->getClass(), |
88
|
57 |
|
]))->render(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return mixed |
94
|
|
|
*/ |
95
|
57 |
|
protected function getDestinationFilePath() |
96
|
|
|
{ |
97
|
57 |
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
98
|
|
|
|
99
|
57 |
|
$generatorPath = $this->laravel['modules']->config('paths.generator.provider'); |
100
|
|
|
|
101
|
57 |
|
return $path.$generatorPath.'/'.$this->getFileName().'.php'; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
57 |
|
private function getFileName() |
109
|
|
|
{ |
110
|
57 |
|
return Str::studly($this->argument('name')); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.