1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\Generators\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
|
8
|
|
|
class CrudControllerBackpackCommand extends GeneratorCommand |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The console command name. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $name = 'backpack:crud-controller'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The name and signature of the console command. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $signature = 'backpack:crud-controller {name}'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The console command description. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Generate a Backpack CRUD controller'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The type of class being generated. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $type = 'Controller'; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the destination class path. |
41
|
|
|
* |
42
|
|
|
* @param string $name |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
protected function getPath($name) |
46
|
|
|
{ |
47
|
|
|
$name = str_replace($this->laravel->getNamespace(), '', $name); |
|
|
|
|
48
|
|
|
|
49
|
|
|
return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'CrudController.php'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the stub file for the generator. |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
protected function getStub() |
58
|
|
|
{ |
59
|
|
|
return __DIR__.'/../stubs/crud-controller.stub'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the default namespace for the class. |
64
|
|
|
* |
65
|
|
|
* @param string $rootNamespace |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
protected function getDefaultNamespace($rootNamespace) |
70
|
|
|
{ |
71
|
|
|
return $rootNamespace.'\Http\Controllers\Admin'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Replace the table name for the given stub. |
76
|
|
|
* |
77
|
|
|
* @param string $stub |
78
|
|
|
* @param string $name |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
protected function replaceNameStrings(&$stub, $name) |
83
|
|
|
{ |
84
|
|
|
$table = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_').'s'; |
85
|
|
|
|
86
|
|
|
$stub = str_replace('DummyTable', $table, $stub); |
87
|
|
|
$stub = str_replace('dummy_class', strtolower(str_replace($this->getNamespace($name).'\\', '', $name)), $stub); |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Build the class with the given name. |
94
|
|
|
* |
95
|
|
|
* @param string $name |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
protected function buildClass($name) |
100
|
|
|
{ |
101
|
|
|
$stub = $this->files->get($this->getStub()); |
102
|
|
|
|
103
|
|
|
return $this->replaceNamespace($stub, $name)->replaceNameStrings($stub, $name)->replaceClass($stub, $name); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get the console command options. |
108
|
|
|
* |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
|
protected function getOptions() |
112
|
|
|
{ |
113
|
|
|
return [ |
114
|
|
|
|
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.