|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PWWEB\Artomator\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use PWWEB\Artomator\Artomator; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
|
|
8
|
|
|
class ArtomatorRequestCommand extends Artomator |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The console command name. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $name = 'artomator:request'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The console command description. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $description = 'Create a new form request class'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The type of class being generated. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $type = 'Request'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get the stub file for the generator. |
|
33
|
|
|
* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function getStub() |
|
37
|
|
|
{ |
|
38
|
|
|
$stub = 'request.stub'; |
|
39
|
|
|
$path = base_path() . config('artomator.stubPath'); |
|
40
|
|
|
$path = $path . $stub; |
|
41
|
|
|
|
|
42
|
|
|
if (file_exists($path) === true) { |
|
43
|
|
|
return $path; |
|
44
|
|
|
} else { |
|
45
|
|
|
return __DIR__ . '/Stubs/' . $stub; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Build the class with the given name. |
|
51
|
|
|
* |
|
52
|
|
|
* Remove the base controller import if we are already in base namespace. |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $name Name of Request to build. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function buildClass($name) |
|
59
|
|
|
{ |
|
60
|
|
|
$replace = parent::buildModelReplacements(); |
|
61
|
|
|
|
|
62
|
|
|
return str_replace( |
|
63
|
|
|
array_keys($replace), |
|
64
|
|
|
array_values($replace), |
|
65
|
|
|
parent::buildClass($name) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the default namespace for the class. |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $rootNamespace The class to return the namespace for. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function getDefaultNamespace($rootNamespace) |
|
77
|
|
|
{ |
|
78
|
|
|
return $rootNamespace . '\Http\Requests'; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get the console command options. |
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function getOptions() |
|
87
|
|
|
{ |
|
88
|
|
|
return [ |
|
89
|
|
|
['model', 'm', InputOption::VALUE_REQUIRED, 'Model name for Validated Request.'], |
|
90
|
|
|
]; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|