1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ikechukwukalu\Makeservice\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
6
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
|
9
|
|
|
#[AsCommand(name: 'make:action')] |
10
|
|
|
class MakeActionCommand extends GeneratorCommand |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The console command name. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $name = 'make:action'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The name of the console command. |
21
|
|
|
* |
22
|
|
|
* This name is used to identify the command during lazy loading. |
23
|
|
|
* |
24
|
|
|
* @var string|null |
25
|
|
|
* |
26
|
|
|
* @deprecated |
27
|
|
|
*/ |
28
|
|
|
protected static $defaultName = 'make:action'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The console command description. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $description = 'Create a new action class'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The type of class being generated. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $type = 'Action'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Determine if the class already exists. |
46
|
|
|
* |
47
|
|
|
* @param string $rawName |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
|
|
protected function alreadyExists($rawName) |
51
|
|
|
{ |
52
|
|
|
return class_exists($rawName) || |
53
|
|
|
$this->files->exists($this->getPath($this->qualifyClass($rawName))); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the stub file for the generator. |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
protected function getStub() |
62
|
|
|
{ |
63
|
|
|
return __DIR__.'/stubs/action.stub'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Resolve the fully-qualified path to the stub. |
68
|
|
|
* |
69
|
|
|
* @param string $stub |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
protected function resolveStubPath($stub) |
73
|
|
|
{ |
74
|
|
|
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) |
75
|
|
|
? $customPath |
76
|
|
|
: __DIR__.$stub; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the default namespace for the class. |
81
|
|
|
* |
82
|
|
|
* @param string $rootNamespace |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
protected function getDefaultNamespace($rootNamespace) |
86
|
|
|
{ |
87
|
|
|
return $rootNamespace.'\Actions'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get the console command options. |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
protected function getOptions() |
96
|
|
|
{ |
97
|
|
|
return [ |
98
|
|
|
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the action already exists'], |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|