|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sco\Admin\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
|
|
8
|
|
|
class ComponentMakeCommand extends GeneratorCommand |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The console command name. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $name = 'make:component'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The console command description. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $description = 'Create a new component class(ScoAdmin)'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The type of class being generated. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $type = 'Component'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Execute the console command. |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function handle() |
|
37
|
|
|
{ |
|
38
|
|
|
if (parent::handle() === false && !$this->option('force')) { |
|
39
|
|
|
return; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if ($this->option('observer')) { |
|
43
|
|
|
$this->createObserver(); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Create a new permission observer for the component |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function createObserver() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->call('make:observer', [ |
|
53
|
|
|
'name' => $this->argument('name') . 'Observer', |
|
54
|
|
|
]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get the stub file for the generator. |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function getStub() |
|
63
|
|
|
{ |
|
64
|
|
|
return __DIR__ . '/stubs/component.stub'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Build the class with the given name. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $name |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function buildClass($name) |
|
75
|
|
|
{ |
|
76
|
|
|
$observerClass = $this->laravel->getNamespace() |
|
77
|
|
|
. 'Observers\\' |
|
78
|
|
|
. $this->argument('name') . 'Observer'; |
|
79
|
|
|
|
|
80
|
|
|
$observer = $this->option('observer') |
|
81
|
|
|
? $observerClass |
|
82
|
|
|
: \Sco\Admin\Component\Observer::class; |
|
83
|
|
|
|
|
84
|
|
|
return str_replace( |
|
85
|
|
|
'DummyObserver', $observer, parent::buildClass($name) |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get the default namespace for the class. |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $rootNamespace |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function getDefaultNamespace($rootNamespace) |
|
97
|
|
|
{ |
|
98
|
|
|
return $rootNamespace . '\Components'; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the console command options. |
|
103
|
|
|
* |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function getOptions() |
|
107
|
|
|
{ |
|
108
|
|
|
return [ |
|
109
|
|
|
[ |
|
110
|
|
|
'observer', 'o', InputOption::VALUE_NONE, |
|
111
|
|
|
'Create a new permission observer for the component', |
|
112
|
|
|
], |
|
113
|
|
|
[ |
|
114
|
|
|
'force', null, InputOption::VALUE_NONE, |
|
115
|
|
|
'Create the class even if the component already exists.', |
|
116
|
|
|
], |
|
117
|
|
|
]; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|