1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace musa11971\SortRequest\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
6
|
|
|
use Illuminate\Contracts\Filesystem\FileNotFoundException; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
|
9
|
|
|
class SorterMakeCommand extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'sort-request:make |
17
|
|
|
{name* : Filter name}'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Create a new Sort Request sorter'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The type of class being generated. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $type = 'Sorter[s]'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Execute the console command. |
35
|
|
|
* |
36
|
|
|
* @throws FileNotFoundException |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
|
public function handle(): void |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
$filters = $this->argument('name'); |
44
|
|
|
|
45
|
|
|
foreach ($filters as $filter) { |
46
|
|
|
$filter = $this->sanitizeNameInput($filter); |
47
|
|
|
$name = $this->qualifyClass($filter); |
48
|
|
|
$path = $this->getPath($name); |
49
|
|
|
$this->makeDirectory($path); |
50
|
|
|
$this->files->put($path, $this->buildClass($name)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->info($this->type.' created successfully.'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the stub file for the generator. |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
protected function getStub(): string |
62
|
|
|
{ |
63
|
|
|
return __DIR__ . '/stubs/sorter.stub'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $name |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
protected function sanitizeNameInput($name): string |
72
|
|
|
{ |
73
|
|
|
return Str::studly(trim($name)) . 'Sorter'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
protected function getDefaultNamespace($rootNamespace): string |
80
|
|
|
{ |
81
|
|
|
return 'App\Http\Sorters'; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|