1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Nwidart\Modules\Support\Config\GenerateConfigReader; |
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 RouteProviderMakeCommand extends GeneratorCommand |
12
|
|
|
{ |
13
|
|
|
use ModuleCommandTrait; |
14
|
|
|
|
15
|
|
|
protected $argumentName = 'module'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The command name. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $name = 'module:route-provider'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The command description. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Create a new route service provider for the specified module.'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The command arguments. |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
94 |
|
protected function getArguments() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
94 |
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the console command options. |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
94 |
|
protected function getOptions() |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
94 |
|
['api', null, InputOption::VALUE_NONE, 'Indicates the api route service provider', null], |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get template contents. |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
86 |
View Code Duplication |
protected function getTemplateContents() |
61
|
|
|
{ |
62
|
86 |
|
$stubFile = $this->option('api') ? '/api-route-provider.stub' : '/route-provider.stub'; |
63
|
|
|
|
64
|
86 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
65
|
|
|
|
66
|
86 |
|
return (new Stub($stubFile, [ |
67
|
86 |
|
'NAMESPACE' => $this->getClassNamespace($module), |
68
|
86 |
|
'CLASS' => $this->getFileName(), |
69
|
86 |
|
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), |
70
|
86 |
|
'MODULE' => $this->getModuleName(), |
71
|
86 |
|
'WEB_ROUTES_PATH' => $this->getWebRoutesPath(), |
72
|
86 |
|
'API_ROUTES_PATH' => $this->getApiRoutesPath(), |
73
|
86 |
|
'LOWER_NAME' => $module->getLowerName(), |
74
|
86 |
|
]))->render(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
86 |
|
private function getFileName() |
81
|
|
|
{ |
82
|
86 |
|
return 'RouteServiceProvider'; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the destination file path. |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
86 |
|
protected function getDestinationFilePath() |
91
|
|
|
{ |
92
|
86 |
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
93
|
|
|
|
94
|
86 |
|
$generatorPath = GenerateConfigReader::read('provider'); |
95
|
|
|
|
96
|
86 |
|
return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php'; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
86 |
|
protected function getWebRoutesPath() |
103
|
|
|
{ |
104
|
86 |
|
return '/' . $this->laravel['config']->get('stubs.files.routes', 'Routes/web.php'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return mixed |
109
|
|
|
*/ |
110
|
86 |
|
protected function getApiRoutesPath() |
111
|
|
|
{ |
112
|
86 |
|
return '/' . $this->laravel['config']->get('stubs.files.routes', 'Routes/api.php'); |
113
|
|
|
} |
114
|
|
|
|
115
|
86 |
|
public function getDefaultNamespace() : string |
116
|
|
|
{ |
117
|
86 |
|
return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers'); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|