1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Recca0120\Generator\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
|
9
|
|
|
class ScaffoldMakeCommand extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The console command name. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'generate:scaffold'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create a new scaffold'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Execute the console command. |
27
|
|
|
* |
28
|
|
|
* @return bool|null |
29
|
|
|
*/ |
30
|
|
|
public function handle() |
31
|
|
|
{ |
32
|
|
|
$name = $this->argument('name'); |
33
|
|
|
|
34
|
|
|
$this->call('generate:controller', ['name' => $name]); |
35
|
|
|
$this->call('generate:view', ['name' => $name, '--view' => 'index']); |
36
|
|
|
$this->call('generate:view', ['name' => $name, '--view' => 'create']); |
37
|
|
|
$this->call('generate:view', ['name' => $name, '--view' => 'edit']); |
38
|
|
|
$this->call('generate:view', ['name' => $name, '--view' => '_form']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get the console command arguments. |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
protected function getArguments() |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
|
|
['name', InputArgument::REQUIRED, 'The name of the class'], |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the console command options. |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
View Code Duplication |
protected function getOptions() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
['extend', '', InputOption::VALUE_OPTIONAL, 'controller extend.'], |
62
|
|
|
['view', '', InputOption::VALUE_OPTIONAL, 'view'], |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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.