@@ 10-95 (lines=86) @@ | ||
7 | use Nwidart\Modules\Traits\ModuleCommandTrait; |
|
8 | use Symfony\Component\Console\Input\InputArgument; |
|
9 | ||
10 | 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 | protected function getArguments() |
|
41 | { |
|
42 | return array( |
|
43 | array('name', InputArgument::REQUIRED, 'The name of the form request class.'), |
|
44 | array('module', InputArgument::OPTIONAL, 'The name of module will be used.'), |
|
45 | ); |
|
46 | } |
|
47 | ||
48 | /** |
|
49 | * @return mixed |
|
50 | */ |
|
51 | protected function getTemplateContents() |
|
52 | { |
|
53 | $module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
|
54 | ||
55 | return (new Stub('/request.stub', [ |
|
56 | 'NAMESPACE' => $this->getClassNamespace($module), |
|
57 | 'CLASS' => $this->getClass(), |
|
58 | 'LOWER_NAME' => $module->getLowerName(), |
|
59 | 'MODULE' => $this->getModuleName(), |
|
60 | 'NAME' => $this->getFileName(), |
|
61 | 'STUDLY_NAME' => $module->getStudlyName(), |
|
62 | 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), |
|
63 | ]))->render(); |
|
64 | } |
|
65 | ||
66 | /** |
|
67 | * @return mixed |
|
68 | */ |
|
69 | protected function getDestinationFilePath() |
|
70 | { |
|
71 | $path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
|
72 | ||
73 | $seederPath = $this->laravel['modules']->config('paths.generator.request'); |
|
74 | ||
75 | return $path.$seederPath.'/'.$this->getFileName().'.php'; |
|
76 | } |
|
77 | ||
78 | /** |
|
79 | * @return string |
|
80 | */ |
|
81 | private function getFileName() |
|
82 | { |
|
83 | return Str::studly($this->argument('name')); |
|
84 | } |
|
85 | ||
86 | /** |
|
87 | * Get default namespace. |
|
88 | * |
|
89 | * @return string |
|
90 | */ |
|
91 | public function getDefaultNamespace() |
|
92 | { |
|
93 | return 'Http\Requests'; |
|
94 | } |
|
95 | } |
|
96 |
@@ 10-95 (lines=86) @@ | ||
7 | use Nwidart\Modules\Traits\ModuleCommandTrait; |
|
8 | use Symfony\Component\Console\Input\InputArgument; |
|
9 | ||
10 | class GenerateMiddlewareCommand 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-middleware'; |
|
27 | ||
28 | /** |
|
29 | * The console command description. |
|
30 | * |
|
31 | * @var string |
|
32 | */ |
|
33 | protected $description = 'Generate new middleware class for the specified module.'; |
|
34 | ||
35 | /** |
|
36 | * Get the console command arguments. |
|
37 | * |
|
38 | * @return array |
|
39 | */ |
|
40 | protected function getArguments() |
|
41 | { |
|
42 | return array( |
|
43 | array('name', InputArgument::REQUIRED, 'The name of the command.'), |
|
44 | array('module', InputArgument::OPTIONAL, 'The name of module will be used.'), |
|
45 | ); |
|
46 | } |
|
47 | ||
48 | /** |
|
49 | * @return mixed |
|
50 | */ |
|
51 | protected function getTemplateContents() |
|
52 | { |
|
53 | $module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
|
54 | ||
55 | return (new Stub('/middleware.stub', [ |
|
56 | 'NAMESPACE' => $this->getClassNamespace($module), |
|
57 | 'CLASS' => $this->getClass(), |
|
58 | 'LOWER_NAME' => $module->getLowerName(), |
|
59 | 'MODULE' => $this->getModuleName(), |
|
60 | 'NAME' => $this->getFileName(), |
|
61 | 'STUDLY_NAME' => $this->getFileName(), |
|
62 | 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), |
|
63 | ]))->render(); |
|
64 | } |
|
65 | ||
66 | /** |
|
67 | * @return mixed |
|
68 | */ |
|
69 | protected function getDestinationFilePath() |
|
70 | { |
|
71 | $path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
|
72 | ||
73 | $seederPath = $this->laravel['modules']->config('paths.generator.filter'); |
|
74 | ||
75 | return $path.$seederPath.'/'.$this->getFileName().'.php'; |
|
76 | } |
|
77 | ||
78 | /** |
|
79 | * @return string |
|
80 | */ |
|
81 | private function getFileName() |
|
82 | { |
|
83 | return Str::studly($this->argument('name')); |
|
84 | } |
|
85 | ||
86 | /** |
|
87 | * Get default namespace. |
|
88 | * |
|
89 | * @return string |
|
90 | */ |
|
91 | public function getDefaultNamespace() |
|
92 | { |
|
93 | return 'Http\Middleware'; |
|
94 | } |
|
95 | } |
|
96 |