1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace EasyPanel\Commands; |
5
|
|
|
|
6
|
|
|
use Illuminate\Console\GeneratorCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
|
9
|
|
|
class MakeCRUDConfig extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
protected $name = 'panel:config'; |
13
|
|
|
protected $type = 'Create a config'; |
14
|
|
|
|
15
|
|
|
protected $description = 'Make a crud config'; |
16
|
|
|
|
17
|
|
|
protected function getStub() |
18
|
|
|
{ |
19
|
|
|
return __DIR__.'/stub/crud.stub'; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function handle() |
23
|
|
|
{ |
24
|
|
|
if(!$this->option()){ |
25
|
|
|
$this->info("model option must have a value"); |
26
|
|
|
return; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$name = strtolower($this->getNameInput()); |
30
|
|
|
|
31
|
|
|
$stub = $this->files->get(__DIR__.'/stub/crud.stub'); |
32
|
|
|
$newStub = $this->parseStub($stub); |
33
|
|
|
|
34
|
|
|
$path = resource_path("cruds/{$name}.php"); |
35
|
|
|
|
36
|
|
|
if (! $this->files->isDirectory(dirname($path))) { |
37
|
|
|
$this->files->makeDirectory(dirname($path), 0755, true); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if($this->files->exists($path) and !$this->option('force')){ |
41
|
|
|
$this->warn("'{$name}' exists in CRUDs config"); |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if($name != strtolower($this->option('model'))){ |
46
|
|
|
$this->warn("'{$name}' must be equal to model name"); |
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->files->put($path, $newStub); |
51
|
|
|
$this->info("{$name} option was created, You can manage it in : resources/cruds/{$name}.php"); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function parseStub($stub) |
55
|
|
|
{ |
56
|
|
|
$model = $this->qualifyModel($this->option('model')); |
|
|
|
|
57
|
|
|
|
58
|
|
|
if(!class_exists($model)){ |
59
|
|
|
$this->warn("Model option should be valid and model should be exist"); |
60
|
|
|
die(); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$array = [ |
64
|
|
|
'{{ model }}' => $model, |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
return str_replace(array_keys($array), array_values($array), $stub); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function getOptions() |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
['force', 'f', InputOption::VALUE_NONE, 'force mode'], |
74
|
|
|
['model', 'm', InputOption::VALUE_REQUIRED, 'model name'], |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|