1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\AdminLTETemplateLaravel\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class MakeView. |
9
|
|
|
* |
10
|
|
|
* @package Acacha\AdminLTETemplateLaravel\Console |
11
|
|
|
*/ |
12
|
|
|
class MakeView extends Command |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The name and signature of the console command. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $signature = 'make:view {name : the name of the view}'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The console command description. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $description = 'Create a new view using adminlte default layout'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create a new command instance. |
30
|
|
|
* |
31
|
|
|
* @return void |
|
|
|
|
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
parent::__construct(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Execute the console command. |
40
|
|
|
* |
41
|
|
|
* |
42
|
|
|
*/ |
43
|
|
|
public function handle() |
44
|
|
|
{ |
45
|
|
|
try { |
46
|
|
|
$this->filesystem->overwrite( |
|
|
|
|
47
|
|
|
$path = resource_path('views/' . $this->viewPath()), |
48
|
|
|
$this->filesystem->get($this->getStubPath()) |
49
|
|
|
); |
50
|
|
|
$this->info('File ' . $path . ' created'); |
51
|
|
|
} catch (\Exception $e) { |
52
|
|
|
print_r($e->getMessage()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get stub path |
58
|
|
|
*/ |
59
|
|
|
protected function getStubPath() |
60
|
|
|
{ |
61
|
|
|
return __DIR__ . '/stubs/view.stub'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* The view destination path. |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
protected function viewPath() |
70
|
|
|
{ |
71
|
|
|
return $this->constructViewBaldeName($this->argument('name')); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Create full relative path to blade template from view name. |
76
|
|
|
* @param $name |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
protected function constructViewBaldeName($name) { |
80
|
|
|
return $this->dottedPathToSlahesPath($name) . '.blade.php'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Converts dotted notation to path slashes. |
85
|
|
|
* @param $name |
86
|
|
|
* @return mixed |
87
|
|
|
*/ |
88
|
|
|
protected function dottedPathToSlahesPath($name) { |
89
|
|
|
return str_replace(".", "/",$name); |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.