1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Pingpong\Support\Stub; |
7
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
|
10
|
|
View Code Duplication |
class MakeRequestCommand extends GeneratorCommand |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
use ModuleCommandTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The name of argument name. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $argumentName = 'name'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The console command name. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $name = 'module:make-request'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The console command description. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $description = 'Generate new form request class for the specified module.'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the console command arguments. |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
16 |
|
protected function getArguments() |
41
|
|
|
{ |
42
|
|
|
return array( |
43
|
16 |
|
array('name', InputArgument::REQUIRED, 'The name of the form request class.'), |
44
|
16 |
|
array('module', InputArgument::OPTIONAL, 'The name of module will be used.'), |
45
|
16 |
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return mixed |
50
|
|
|
*/ |
51
|
2 |
|
protected function getTemplateContents() |
52
|
|
|
{ |
53
|
2 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
54
|
|
|
|
55
|
2 |
|
return (new Stub('/request.stub', [ |
56
|
2 |
|
'NAMESPACE' => $this->getClassNamespace($module), |
57
|
2 |
|
'CLASS' => $this->getClass(), |
58
|
2 |
|
'LOWER_NAME' => $module->getLowerName(), |
59
|
2 |
|
'MODULE' => $this->getModuleName(), |
60
|
2 |
|
'NAME' => $this->getFileName(), |
61
|
2 |
|
'STUDLY_NAME' => $module->getStudlyName(), |
62
|
2 |
|
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), |
63
|
2 |
|
]))->render(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
2 |
|
protected function getDestinationFilePath() |
70
|
|
|
{ |
71
|
2 |
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
72
|
|
|
|
73
|
2 |
|
$seederPath = $this->laravel['modules']->config('paths.generator.request'); |
74
|
|
|
|
75
|
2 |
|
return $path.$seederPath.'/'.$this->getFileName().'.php'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
2 |
|
private function getFileName() |
82
|
|
|
{ |
83
|
2 |
|
return Str::studly($this->argument('name')); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get default namespace. |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
2 |
|
public function getDefaultNamespace() |
92
|
|
|
{ |
93
|
2 |
|
return 'Http\Requests'; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.