|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Consigliere\Components\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Consigliere\Components\Support\Stub; |
|
6
|
|
|
use Consigliere\Components\Traits\ComponentCommandTrait; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
|
|
9
|
|
|
class GenerateRouteProviderCommand extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
use ComponentCommandTrait; |
|
12
|
|
|
|
|
13
|
|
|
protected $argumentName = 'component'; |
|
14
|
|
|
/** |
|
15
|
|
|
* The command name. |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $name = 'component:route-provider'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The command description. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $description = 'Generate a new route service provider for the specified component.'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The command arguments. |
|
30
|
|
|
* |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function getArguments() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
['component', InputArgument::OPTIONAL, 'The name of component will be used.'], |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get template contents. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function getTemplateContents() |
|
46
|
|
|
{ |
|
47
|
|
|
$component = $this->laravel['components']->findOrFail($this->getComponentName()); |
|
48
|
|
|
|
|
49
|
|
|
return (new Stub('/route-provider.stub', [ |
|
50
|
|
|
'NAMESPACE' => $this->getClassNamespace($component), |
|
51
|
|
|
'CLASS' => $this->getClass(), |
|
52
|
|
|
'LOWER_NAME' => $component->getLowerName(), |
|
53
|
|
|
'COMPONENT' => $this->getComponentName(), |
|
54
|
|
|
'NAME' => $this->getFileName(), |
|
55
|
|
|
'STUDLY_NAME' => $component->getStudlyName(), |
|
56
|
|
|
'COMPONENT_NAMESPACE' => $this->laravel['components']->config('namespace'), |
|
57
|
|
|
]))->render(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the destination file path. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function getDestinationFilePath() |
|
66
|
|
|
{ |
|
67
|
|
|
$path = $this->laravel['components']->getComponentPath($this->getComponentName()); |
|
68
|
|
|
|
|
69
|
|
|
$generatorPath = $this->laravel['components']->config('paths.generator.provider'); |
|
70
|
|
|
|
|
71
|
|
|
return $path . $generatorPath . '/' . $this->getFileName() . '.php'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
private function getFileName() |
|
78
|
|
|
{ |
|
79
|
|
|
return 'RouteServiceProvider'; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|