1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larafast\Fastapi\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Larafast\Fastapi\Console\Contracts\GeneratorCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
|
9
|
|
|
class RequestMakeCommand extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The console command name. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'fastApi:request'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create a new form request class'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The type of class being generated. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $type = 'Request'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the stub file for the generator. |
34
|
|
|
* |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
|
|
protected function getStub() |
38
|
|
|
{ |
39
|
|
|
if (!$this->option('type') || $this->option('type') == 'store') { |
40
|
|
|
return config('fastApi.stubs_dir') . '/request.stub'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return config('fastApi.stubs_dir') . '/request.update.stub'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function buildClass($name) |
47
|
|
|
{ |
48
|
|
|
$replace = []; |
49
|
|
|
if ($model = $this->option('model')) { |
|
|
|
|
50
|
|
|
$model = Str::studly(class_basename($this->option('model'))); |
|
|
|
|
51
|
|
|
$slug = Str::slug(str_to_words($model), '_'); |
52
|
|
|
$replace['$modelSlug$'] = $slug; |
53
|
|
|
$replace['$modelTable$'] = Str::plural($slug, 2); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return str_replace( |
57
|
|
|
array_keys($replace), array_values($replace), parent::buildClass($name) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the default namespace for the class. |
63
|
|
|
* |
64
|
|
|
* @param string $rootNamespace |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
protected function getDefaultNamespace($rootNamespace) |
69
|
|
|
{ |
70
|
|
|
return $rootNamespace . '\Http\Requests'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the console command options. |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
protected function getOptions() |
79
|
|
|
{ |
80
|
|
|
return [ |
81
|
|
|
['model', 'm', InputOption::VALUE_REQUIRED, 'The given model.'], |
82
|
|
|
['type', 't', InputOption::VALUE_OPTIONAL, 'Type of request. Values can be store or update'], |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|