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