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 AuthRoutesResource extends PackageResource |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Create a new resource instance. |
12
|
|
|
* |
13
|
|
|
* @return void |
14
|
|
|
*/ |
15
|
24 |
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
// Fill the resource data. |
18
|
|
|
|
19
|
24 |
|
$this->description = 'The set of routes for the Laravel/UI auth scaffolding'; |
20
|
24 |
|
$this->source = CommandHelper::getStubPath('routes.stub'); |
21
|
24 |
|
$this->target = base_path('routes/web.php'); |
22
|
24 |
|
$this->required = false; |
23
|
|
|
|
24
|
|
|
// Fill the installation messages. |
25
|
|
|
|
26
|
24 |
|
$this->messages = [ |
27
|
24 |
|
'install' => 'Do you want to publish the Laravel/UI auth routes?', |
28
|
24 |
|
'overwrite' => 'The auth routes were already published. Want to publish again?', |
29
|
24 |
|
'success' => 'Auth routes published successfully', |
30
|
24 |
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Installs or publishes the resource. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
6 |
|
public function install() |
39
|
|
|
{ |
40
|
|
|
// If the routes already exists, we won't publish they again. |
41
|
|
|
|
42
|
6 |
|
if ($this->exists()) { |
43
|
1 |
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// Get the set of routes to be published. |
47
|
|
|
|
48
|
5 |
|
$routes = File::get($this->source); |
49
|
|
|
|
50
|
|
|
// Add the routes to the web routes file. |
51
|
|
|
|
52
|
5 |
|
File::ensureDirectoryExists(File::dirname($this->target)); |
53
|
5 |
|
File::append($this->target, $routes); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Uninstalls the resource. |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
6 |
|
public function uninstall() |
62
|
|
|
{ |
63
|
|
|
// Get the set of routes to be removed. |
64
|
|
|
|
65
|
6 |
|
$routes = File::get($this->source); |
66
|
|
|
|
67
|
|
|
// If the target routes file exists, then remove the auth routes. |
68
|
|
|
// Otherwise, we consider the routes as uninstalled. |
69
|
|
|
|
70
|
6 |
|
if (File::isFile($this->target)) { |
71
|
6 |
|
$targetContent = File::get($this->target); |
72
|
6 |
|
$targetContent = str_replace($routes, '', $targetContent); |
73
|
6 |
|
File::put($this->target, $targetContent); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Checks whether the resource already exists in the target location. |
79
|
|
|
* |
80
|
|
|
* @return bool |
81
|
|
|
*/ |
82
|
7 |
|
public function exists() |
83
|
|
|
{ |
84
|
7 |
|
$routes = File::get($this->source); |
85
|
|
|
|
86
|
|
|
// Check whether the target routes file exists and contains the |
87
|
|
|
// expected routes. |
88
|
|
|
|
89
|
7 |
|
return File::isFile($this->target) |
90
|
7 |
|
&& (strpos(File::get($this->target), $routes) !== false); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Checks whether the resource is correctly installed, i.e. if the source |
95
|
|
|
* items matches with the items available at the target location. |
96
|
|
|
* |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
7 |
|
public function installed() |
100
|
|
|
{ |
101
|
7 |
|
return $this->exists(); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|