1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Facade\Ignition\Solutions; |
4
|
|
|
|
5
|
|
|
use Facade\IgnitionContracts\RunnableSolution; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
|
8
|
|
|
class UseDefaultValetDbCredentialsSolution implements RunnableSolution |
9
|
|
|
{ |
10
|
|
|
public function getSolutionActionDescription(): string |
11
|
|
|
{ |
12
|
|
|
return 'Pressing the button below will change `DB_USER` and `DB_PASSWORD` in your `.env` file.'; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function getRunButtonText(): string |
16
|
|
|
{ |
17
|
|
|
return 'Use default Valet credentials'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getSolutionTitle(): string |
21
|
|
|
{ |
22
|
|
|
return 'Could not connect to database'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function run(array $parameters = []) |
26
|
|
|
{ |
27
|
|
|
if (! file_exists(base_path('.env'))) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$this->ensureLineExists('DB_USERNAME', 'root'); |
32
|
|
|
$this->ensureLineExists('DB_PASSWORD', ''); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function ensureLineExists(string $key, string $value) |
36
|
|
|
{ |
37
|
|
|
$envPath = base_path('.env'); |
38
|
|
|
|
39
|
|
|
$envLines = array_map(function (string $envLine) use ($value, $key) { |
40
|
|
|
return Str::startsWith($envLine, $key) |
41
|
|
|
? "{$key}={$value}".PHP_EOL |
42
|
|
|
: $envLine; |
43
|
|
|
}, file($envPath)); |
44
|
|
|
|
45
|
|
|
file_put_contents($envPath, implode('', $envLines)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getDocumentationLinks(): array |
49
|
|
|
{ |
50
|
|
|
return []; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getRunParameters(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'Valet documentation' => 'https://laravel.com/docs/master/valet', |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getSolutionDescription(): string |
61
|
|
|
{ |
62
|
|
|
return 'You seem to be using Valet, but the .env file does not contain the right default database credentials.'; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|