|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
|
|
|
|
|
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class PanelMakeCommand extends GeneratorCommand |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The console command name. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $name = 'administrator:panel'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Create new administrator dashboard panel.'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The type of class being generated. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $type = 'Dashboard'; |
|
31
|
|
|
|
|
32
|
|
|
public function handle() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::handle(); |
|
35
|
|
|
|
|
36
|
|
|
if (!$this->option('no-view')) { |
|
37
|
|
|
$name = class_basename($this->qualifyClass($this->getNameInput())); |
|
38
|
|
|
|
|
39
|
|
|
$view = $this->templatePath($this->getViewName()); |
|
40
|
|
|
|
|
41
|
|
|
$this->makeDirectory($view); |
|
42
|
|
|
|
|
43
|
|
|
$this->files->put($view, $this->templateContents( |
|
44
|
|
|
$name, |
|
45
|
|
|
ltrim(str_replace(base_path(), '', $view), \DIRECTORY_SEPARATOR) |
|
|
|
|
|
|
46
|
|
|
)); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Replace the class name for the given stub. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $stub |
|
54
|
|
|
* @param string $name |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function replaceClass($stub, $name) |
|
59
|
|
|
{ |
|
60
|
|
|
$class = str_replace($this->getNamespace($name).'\\', '', $name); |
|
61
|
|
|
$view = $this->getViewName(); |
|
62
|
|
|
|
|
63
|
|
|
$stub = str_replace('DummyClass', $class, $stub); |
|
64
|
|
|
|
|
65
|
|
|
return str_replace('DummyTemplate', 'admin.dashboard.'.$view, $stub); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the stub file for the generator. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getStub() |
|
74
|
|
|
{ |
|
75
|
|
|
if ($this->option('no-view')) { |
|
76
|
|
|
return __DIR__.'/stubs/dashboard.panel.simple.stub'; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return __DIR__.'/stubs/dashboard.panel.stub'; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get the default namespace for the class. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $rootNamespace |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function getDefaultNamespace($rootNamespace) |
|
90
|
|
|
{ |
|
91
|
|
|
return $rootNamespace.'\\'.config('administrator.paths.panel'); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get the console command options. |
|
96
|
|
|
* |
|
97
|
|
|
* @return array |
|
98
|
|
|
*/ |
|
99
|
|
|
protected function getOptions() |
|
100
|
|
|
{ |
|
101
|
|
|
return [ |
|
102
|
|
|
['no-view', null, InputOption::VALUE_NONE, 'Do not generate view template for this panel.'], |
|
103
|
|
|
]; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param $name |
|
108
|
|
|
* |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function templatePath($name) |
|
112
|
|
|
{ |
|
113
|
|
|
$tpl = base_path('resources/views/admin/dashboard/'.$name.'.blade.php'); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
return $tpl; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function getViewName() |
|
122
|
|
|
{ |
|
123
|
|
|
return Str::snake(class_basename($this->qualifyClass($this->getNameInput()))); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
private function templateContents($title, $path) |
|
127
|
|
|
{ |
|
128
|
|
|
return <<<OUT |
|
129
|
|
|
<div class="panel"> |
|
130
|
|
|
<div class="panel-heading"> |
|
131
|
|
|
<h4 class="panel-title">{$title}</h4> |
|
132
|
|
|
</div> |
|
133
|
|
|
<div class="panel-body"> |
|
134
|
|
|
<p class="well">Check me out here [{$path}]</p> |
|
135
|
|
|
</div> |
|
136
|
|
|
</div> |
|
137
|
|
|
OUT; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths