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