|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\PermissionManager\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
|
6
|
|
|
|
|
7
|
|
|
class ExtendPermissionCrudRequest extends GeneratorCommand |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The console command name. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $name = 'backpack:crud-permission-request'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The name and signature of the console command. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $signature = 'backpack:crud-permission-request {name}'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The console command description. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $description = 'Generate a Backpack CRUD Permission request'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The type of class being generated. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $type = 'Request'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get the stub file for the generator. |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function getStub() |
|
43
|
|
|
{ |
|
44
|
|
|
return __DIR__.'/../stubs/crud-request-permission.stub'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get the destination class path. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $name |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
protected function getPath($name) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
// Get relative path name |
|
57
|
|
|
$name = str_replace_first($this->laravel->getNamespace(), '', $name); |
|
58
|
|
|
$name = str_replace('\\', '/', $name); |
|
59
|
|
|
|
|
60
|
|
|
// Pull expected filename from path |
|
61
|
|
|
$name_array = explode('/', $name); |
|
62
|
|
|
$file = array_pop($name_array); |
|
63
|
|
|
// Replace with Extended version |
|
64
|
|
|
$name_array[] = 'Extend'.$file; |
|
65
|
|
|
|
|
66
|
|
|
// Implode array to string |
|
67
|
|
|
$name = implode('/', $name_array); |
|
68
|
|
|
|
|
69
|
|
|
// Return new path |
|
70
|
|
|
return $this->laravel['path'].'/'.$name.'CrudRequest.php'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get the default namespace for the class. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $rootNamespace |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function getDefaultNamespace($rootNamespace) |
|
81
|
|
|
{ |
|
82
|
|
|
return $rootNamespace.'\Http\Requests\Permissions'; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get the console command options. |
|
87
|
|
|
* |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function getOptions() |
|
91
|
|
|
{ |
|
92
|
|
|
return [ |
|
93
|
|
|
|
|
94
|
|
|
]; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
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.