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
|
91 |
|
protected function getArguments() |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
91 |
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get template contents. |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
3 |
|
protected function getTemplateContents() |
48
|
|
|
{ |
49
|
3 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
50
|
|
|
|
51
|
3 |
|
return (new Stub('/route-provider.stub', [ |
52
|
3 |
|
'NAMESPACE' => $this->getClassNamespace($module), |
53
|
3 |
|
'CLASS' => $this->getFileName(), |
54
|
3 |
|
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), |
55
|
3 |
|
'MODULE' => $this->getModuleName(), |
56
|
3 |
|
'ROUTES_PATH' => $this->getRoutesPath(), |
57
|
3 |
|
]))->render(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
3 |
|
private function getFileName() |
64
|
|
|
{ |
65
|
3 |
|
return 'RouteServiceProvider'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the destination file path. |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
3 |
|
protected function getDestinationFilePath() |
74
|
|
|
{ |
75
|
3 |
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
76
|
|
|
|
77
|
3 |
|
$generatorPath = GenerateConfigReader::read('provider'); |
78
|
|
|
|
79
|
3 |
|
return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php'; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return mixed |
84
|
|
|
*/ |
85
|
3 |
|
protected function getRoutesPath() |
86
|
|
|
{ |
87
|
3 |
|
return '/' . $this->laravel['config']->get('stubs.files.routes', 'Http/routes.php'); |
88
|
|
|
} |
89
|
|
|
|
90
|
3 |
|
public function getDefaultNamespace() : string |
91
|
|
|
{ |
92
|
3 |
|
return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers'); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|