1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Milkmeowo\Framework\Repository\Generators\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
|
10
|
|
|
class EntityCommand extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The name of command. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $name = 'starter:entity'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The description of command. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Create a new entity.'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var Collection |
28
|
|
|
*/ |
29
|
|
|
protected $generators = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Execute the command. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function fire() |
37
|
|
|
{ |
38
|
|
|
$this->call('starter:presenter', [ |
39
|
|
|
'name' => $this->argument('name'), |
40
|
|
|
'--force' => $this->option('force'), |
41
|
|
|
]); |
42
|
|
|
|
43
|
|
|
$this->call('starter:validator', [ |
44
|
|
|
'name' => $this->argument('name'), |
45
|
|
|
'--rules' => $this->option('rules'), |
46
|
|
|
'--force' => $this->option('force'), |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
// Generate a controller resource |
50
|
|
|
$this->call('starter:resource', [ |
51
|
|
|
'name' => $this->argument('name'), |
52
|
|
|
'--force' => $this->option('force'), |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
$this->call('starter:repository', [ |
56
|
|
|
'name' => $this->argument('name'), |
57
|
|
|
'--fillable' => $this->option('fillable'), |
58
|
|
|
'--rules' => $this->option('rules'), |
59
|
|
|
'--validator' => 'yes', |
60
|
|
|
'--presenter' => 'yes', |
61
|
|
|
'--force' => $this->option('force'), |
62
|
|
|
]); |
63
|
|
|
|
64
|
|
|
$this->call('starter:bindings', [ |
65
|
|
|
'name' => $this->argument('name'), |
66
|
|
|
'--force' => $this->option('force'), |
67
|
|
|
]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The array of command arguments. |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function getArguments() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
[ |
79
|
|
|
'name', |
80
|
|
|
InputArgument::REQUIRED, |
81
|
|
|
'The name of class being generated.', |
82
|
|
|
null, |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* The array of command options. |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
public function getOptions() |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
return [ |
95
|
|
|
[ |
96
|
|
|
'fillable', |
97
|
|
|
null, |
98
|
|
|
InputOption::VALUE_OPTIONAL, |
99
|
|
|
'The fillable attributes.', |
100
|
|
|
null, |
101
|
|
|
], |
102
|
|
|
[ |
103
|
|
|
'rules', |
104
|
|
|
null, |
105
|
|
|
InputOption::VALUE_OPTIONAL, |
106
|
|
|
'The rules of validation attributes.', |
107
|
|
|
null, |
108
|
|
|
], |
109
|
|
|
[ |
110
|
|
|
'validator', |
111
|
|
|
null, |
112
|
|
|
InputOption::VALUE_OPTIONAL, |
113
|
|
|
'Adds validator reference to the repository.', |
114
|
|
|
null, |
115
|
|
|
], |
116
|
|
|
[ |
117
|
|
|
'presenter', |
118
|
|
|
null, |
119
|
|
|
InputOption::VALUE_OPTIONAL, |
120
|
|
|
'Adds presenter reference to the repository.', |
121
|
|
|
null, |
122
|
|
|
], |
123
|
|
|
[ |
124
|
|
|
'force', |
125
|
|
|
'f', |
126
|
|
|
InputOption::VALUE_NONE, |
127
|
|
|
'Force the creation if file already exists.', |
128
|
|
|
null, |
129
|
|
|
], |
130
|
|
|
]; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
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.