1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Some of logic is used from jeroennoten/Laravel-AdminLTE Many thanks to the maintainers |
4
|
|
|
* you can checkout the package from here: https://github.com/jeroennoten/Laravel-AdminLTE |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Aminetiyal\LaravelTemplate\Commands; |
8
|
|
|
|
9
|
|
|
use Illuminate\Console\Command; |
10
|
|
|
use Illuminate\Support\Facades\File; |
11
|
|
|
|
12
|
|
|
class TemplateInstall extends Command |
13
|
|
|
{ |
14
|
|
|
protected $signature = 'template:install' . |
15
|
|
|
'{--routes : Add template routes}' . |
16
|
|
|
'{--auth : Update Auth views}' . |
17
|
|
|
'{--home : Update Home view}'; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected $description = 'Install template package'; |
21
|
|
|
|
22
|
|
|
protected $authViews = [ |
23
|
|
|
'views/auth/login.blade.php' => '@extends(\'template::lte.login\')', |
24
|
|
|
'views/auth/register.blade.php' => '@extends(\'template::lte.register\')', |
25
|
|
|
'views/auth/verify.blade.php' => '@extends(\'template::lte.verify\')', |
26
|
|
|
'views/auth/passwords/confirm.blade.php' => '@extends(\'template::lte.passwords.confirm\')', |
27
|
|
|
'views/auth/passwords/email.blade.php' => '@extends(\'template::lte.passwords.email\')', |
28
|
|
|
'views/auth/passwords/reset.blade.php' => '@extends(\'template::lte.passwords.reset\')', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
protected $homeView = 'views/home.blade.php'; |
32
|
|
|
|
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
parent::__construct(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function handle() |
39
|
|
|
{ |
40
|
|
|
if ($this->option('routes')) { |
41
|
|
|
$this->exportRoutes(); |
42
|
|
|
} |
43
|
|
|
if ($this->option('home')) { |
44
|
|
|
$this->exportHomeView(); |
45
|
|
|
} |
46
|
|
|
if ($this->option('auth')) { |
47
|
|
|
$this->exportAuthViews(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function exportHomeView() |
52
|
|
|
{ |
53
|
|
|
if (!$this->confirm('Install Home view?')) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$content = File::get(__DIR__ . '/stubs/home.blade.stub'); |
58
|
|
|
|
59
|
|
|
file_put_contents(resource_path($this->homeView), $content); |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->comment('Home view updated successfully.'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function exportAuthViews() |
66
|
|
|
{ |
67
|
|
|
if (!$this->confirm('Install Template authentication views?')) { |
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// create auth directory if not exists |
72
|
|
|
if (!File::isDirectory(resource_path('/views/auth'))) { |
73
|
|
|
File::makeDirectory(resource_path('views/auth'), 0755, true); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
foreach ($this->authViews as $file => $content) { |
77
|
|
|
file_put_contents(resource_path($file), $content); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->call('vendor:publish', ['--tag' => 'template-profile-controller']); |
81
|
|
|
$this->call('vendor:publish', ['--tag' => 'template-profile-view']); |
82
|
|
|
|
83
|
|
|
$this->comment('Authentication views updated successfully.'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function exportRoutes() |
87
|
|
|
{ |
88
|
|
|
if (!$this->confirm('Install Profile Routes?')) { |
89
|
|
|
return; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$file = File::get(base_path('routes/web.php')); |
93
|
|
|
$content = File::get(__DIR__ . '/stubs/routes.stub'); |
94
|
|
|
|
95
|
|
|
if (!strpos($file, $content)) { |
96
|
|
|
File::append( |
97
|
|
|
base_path('routes/web.php'), |
98
|
|
|
file_get_contents(__DIR__.'/stubs/routes.stub'), |
99
|
|
|
FILE_APPEND |
|
|
|
|
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$this->comment('Profile routes installed successfully.'); |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.