|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Foundation\Generator\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use Nwidart\Modules\Module; |
|
7
|
|
|
use Nwidart\Modules\Support\Config\GenerateConfigReader; |
|
8
|
|
|
use Nwidart\Modules\Support\Stub; |
|
9
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
12
|
|
|
|
|
13
|
|
|
class ProviderMakeCommand extends \Nwidart\Modules\Commands\ProviderMakeCommand |
|
14
|
|
|
{ |
|
15
|
|
|
use ModuleCommandTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The name of argument name. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $argumentName = 'name'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The console command name. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $name = 'module:make-provider'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The console command description. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $description = 'Create a new service provider class for the specified module.'; |
|
37
|
|
|
|
|
38
|
|
|
public function getDefaultNamespace() : string |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get the console command arguments. |
|
45
|
|
|
* |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function getArguments() |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
['name', InputArgument::REQUIRED, 'The service provider name.'], |
|
52
|
|
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the console command options. |
|
58
|
|
|
* |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function getOptions() |
|
62
|
|
|
{ |
|
63
|
|
|
return [ |
|
64
|
|
|
['master', null, InputOption::VALUE_NONE, 'Indicates the master service provider', null], |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function getTemplateContents() |
|
72
|
|
|
{ |
|
73
|
|
|
$stub = $this->option('master') ? 'scaffold/provider' : 'provider'; |
|
74
|
|
|
|
|
75
|
|
|
/** @var Module $module */ |
|
76
|
|
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
|
77
|
|
|
|
|
78
|
|
|
return (new Stub('/' . $stub . '.stub', [ |
|
79
|
|
|
'NAMESPACE' => $this->getClassNamespace($module), |
|
80
|
|
|
'CLASS' => $this->getClass(), |
|
81
|
|
|
'LOWER_NAME' => $module->getLowerName(), |
|
82
|
|
|
'MODULE' => $this->getModuleName(), |
|
83
|
|
|
'NAME' => $this->getFileName(), |
|
84
|
|
|
'STUDLY_NAME' => $module->getStudlyName(), |
|
85
|
|
|
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), |
|
86
|
|
|
'PATH_VIEWS' => GenerateConfigReader::read('views')->getPath(), |
|
87
|
|
|
'PATH_LANG' => GenerateConfigReader::read('lang')->getPath(), |
|
88
|
|
|
'PATH_CONFIG' => GenerateConfigReader::read('config')->getPath(), |
|
89
|
|
|
'MIGRATIONS_PATH' => GenerateConfigReader::read('migration')->getPath(), |
|
90
|
|
|
'FACTORIES_PATH' => GenerateConfigReader::read('factory')->getPath(), |
|
91
|
|
|
]))->render(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return mixed |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function getDestinationFilePath() |
|
98
|
|
|
{ |
|
99
|
|
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
|
100
|
|
|
|
|
101
|
|
|
$generatorPath = GenerateConfigReader::read('provider'); |
|
102
|
|
|
|
|
103
|
|
|
return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php'; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
|
|
private function getFileName() |
|
110
|
|
|
{ |
|
111
|
|
|
return Str::studly($this->argument('name')); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|