|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Console\PackageResources; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\File; |
|
6
|
|
|
use JeroenNoten\LaravelAdminLte\Helpers\CommandHelper; |
|
7
|
|
|
|
|
8
|
|
|
class AuthViewsResource extends PackageResource |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Array with the replacement content for the authentication views of the |
|
12
|
|
|
* legacy Laravel/UI package. |
|
13
|
|
|
* |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $authViewsContent = [ |
|
17
|
|
|
'login.blade.php' => '@extends(\'adminlte::auth.login\')', |
|
18
|
|
|
'register.blade.php' => '@extends(\'adminlte::auth.register\')', |
|
19
|
|
|
'verify.blade.php' => '@extends(\'adminlte::auth.verify\')', |
|
20
|
|
|
'passwords/confirm.blade.php' => '@extends(\'adminlte::auth.passwords.confirm\')', |
|
21
|
|
|
'passwords/email.blade.php' => '@extends(\'adminlte::auth.passwords.email\')', |
|
22
|
|
|
'passwords/reset.blade.php' => '@extends(\'adminlte::auth.passwords.reset\')', |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Create a new resource instance. |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
23 |
|
public function __construct() |
|
31
|
|
|
{ |
|
32
|
|
|
// Fill the resource data. |
|
33
|
|
|
|
|
34
|
23 |
|
$this->description = 'The set of AdminLTE replacement auth views for the Laravel/UI package'; |
|
35
|
23 |
|
$this->source = $this->authViewsContent; |
|
36
|
23 |
|
$this->target = CommandHelper::getViewPath('auth'); |
|
37
|
23 |
|
$this->required = false; |
|
38
|
|
|
|
|
39
|
|
|
// Fill the set of installation messages. |
|
40
|
|
|
|
|
41
|
23 |
|
$this->messages = [ |
|
42
|
23 |
|
'install' => 'Do you want to publish the replacement auth views for Laravel/UI?', |
|
43
|
23 |
|
'overwrite' => 'The auth views were already published. Want to replace?', |
|
44
|
23 |
|
'success' => 'Auth views published successfully', |
|
45
|
23 |
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Installs or publishes the resource. |
|
50
|
|
|
* |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
8 |
|
public function install() |
|
54
|
|
|
{ |
|
55
|
|
|
// Publish the authentication views. We actually need to replace the |
|
56
|
|
|
// content of any existing authentication view that were originally |
|
57
|
|
|
// provided by the legacy Laravel/UI package. |
|
58
|
|
|
|
|
59
|
8 |
|
foreach ($this->source as $file => $content) { |
|
60
|
8 |
|
$target = $this->target.DIRECTORY_SEPARATOR.$file; |
|
61
|
8 |
|
File::ensureDirectoryExists(File::dirname($target)); |
|
62
|
8 |
|
File::put($target, $content); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Uninstalls the resource. |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
8 |
|
public function uninstall() |
|
72
|
|
|
{ |
|
73
|
|
|
// Remove the published authentication views. |
|
74
|
|
|
|
|
75
|
8 |
|
foreach ($this->source as $file => $content) { |
|
76
|
8 |
|
$target = $this->target.DIRECTORY_SEPARATOR.$file; |
|
77
|
|
|
|
|
78
|
8 |
|
if (File::isFile($target)) { |
|
79
|
8 |
|
File::delete($target); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Checks whether the resource already exists in the target location. |
|
86
|
|
|
* |
|
87
|
|
|
* @return bool |
|
88
|
|
|
*/ |
|
89
|
9 |
|
public function exists() |
|
90
|
|
|
{ |
|
91
|
|
|
// Check if any of the authentication views is published. We need to |
|
92
|
|
|
// check that at least one of the target files exists and the |
|
93
|
|
|
// replacement content is present. |
|
94
|
|
|
|
|
95
|
9 |
|
foreach ($this->source as $file => $content) { |
|
96
|
9 |
|
$target = $this->target.DIRECTORY_SEPARATOR.$file; |
|
97
|
|
|
|
|
98
|
9 |
|
if ($this->authViewExists($target, $content)) { |
|
99
|
1 |
|
return true; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
8 |
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Checks whether the resource is correctly installed, i.e. if the source |
|
108
|
|
|
* items matches with the items available at the target location. |
|
109
|
|
|
* |
|
110
|
|
|
* @return bool |
|
111
|
|
|
*/ |
|
112
|
9 |
|
public function installed() |
|
113
|
|
|
{ |
|
114
|
9 |
|
foreach ($this->source as $file => $content) { |
|
115
|
9 |
|
$target = $this->target.DIRECTORY_SEPARATOR.$file; |
|
116
|
|
|
|
|
117
|
9 |
|
if (! $this->authViewInstalled($target, $content)) { |
|
118
|
4 |
|
return false; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
8 |
|
return true; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Checks whether an authentication view exists. |
|
127
|
|
|
* |
|
128
|
|
|
* @param string $path Absolute path of the authentication view |
|
129
|
|
|
* @param string $content The expected content of the view |
|
130
|
|
|
* @return bool |
|
131
|
|
|
*/ |
|
132
|
9 |
|
protected function authViewExists($path, $content) |
|
133
|
|
|
{ |
|
134
|
9 |
|
return File::isFile($path) |
|
135
|
9 |
|
&& strpos(File::get($path), $content) !== false; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Checks whether an authentication view is correctly installed. |
|
140
|
|
|
* |
|
141
|
|
|
* @param string $path Absolute path of the authentication view |
|
142
|
|
|
* @param string $content The expected content of the view |
|
143
|
|
|
* @return bool |
|
144
|
|
|
*/ |
|
145
|
9 |
|
protected function authViewInstalled($path, $content) |
|
146
|
|
|
{ |
|
147
|
9 |
|
return File::isFile($path) && File::get($path) === $content; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|