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
|
95 |
|
*/ |
36
|
|
|
protected function getArguments() |
37
|
|
|
{ |
38
|
95 |
|
return [ |
39
|
|
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function getOptions() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when the file already exists.'], |
47
|
87 |
|
]; |
48
|
|
|
} |
49
|
87 |
|
|
50
|
|
|
/** |
51
|
87 |
|
* Get template contents. |
52
|
87 |
|
* |
53
|
87 |
|
* @return string |
54
|
87 |
|
*/ |
55
|
87 |
View Code Duplication |
protected function getTemplateContents() |
56
|
87 |
|
{ |
57
|
87 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
58
|
87 |
|
|
59
|
87 |
|
return (new Stub('/route-provider.stub', [ |
60
|
|
|
'NAMESPACE' => $this->getClassNamespace($module), |
61
|
|
|
'CLASS' => $this->getFileName(), |
62
|
|
|
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), |
63
|
|
|
'MODULE' => $this->getModuleName(), |
64
|
|
|
'WEB_ROUTES_PATH' => $this->getWebRoutesPath(), |
65
|
87 |
|
'API_ROUTES_PATH' => $this->getApiRoutesPath(), |
66
|
|
|
'LOWER_NAME' => $module->getLowerName(), |
67
|
87 |
|
]))->render(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
private function getFileName() |
74
|
|
|
{ |
75
|
87 |
|
return 'RouteServiceProvider'; |
76
|
|
|
} |
77
|
87 |
|
|
78
|
|
|
/** |
79
|
87 |
|
* Get the destination file path. |
80
|
|
|
* |
81
|
87 |
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
protected function getDestinationFilePath() |
84
|
|
|
{ |
85
|
|
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
86
|
|
|
|
87
|
87 |
|
$generatorPath = GenerateConfigReader::read('provider'); |
88
|
|
|
|
89
|
87 |
|
return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return mixed |
94
|
|
|
*/ |
95
|
87 |
|
protected function getWebRoutesPath() |
96
|
|
|
{ |
97
|
87 |
|
return '/' . $this->laravel['modules']->config('stubs.files.routes/web', 'Routes/web.php'); |
98
|
|
|
} |
99
|
|
|
|
100
|
87 |
|
/** |
101
|
|
|
* @return mixed |
102
|
87 |
|
*/ |
103
|
|
|
protected function getApiRoutesPath() |
104
|
|
|
{ |
105
|
|
|
return '/' . $this->laravel['modules']->config('stubs.files.routes/api', 'Routes/api.php'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getDefaultNamespace() : string |
109
|
|
|
{ |
110
|
|
|
return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|