|
6 | 6 | use Cachet\Settings\AppSettings; |
7 | 7 | use Cachet\Settings\Attributes\Description; |
8 | 8 | use Illuminate\Console\Command; |
| 9 | +use Illuminate\Support\Facades\File; |
9 | 10 | use Illuminate\Support\Sleep; |
| 11 | +use Illuminate\Support\Str; |
10 | 12 | use ReflectionClass; |
11 | 13 | use ReflectionProperty; |
12 | 14 | use function Laravel\Prompts\confirm; |
@@ -48,7 +50,67 @@ public function handle(AppSettings $settings) |
48 | 50 |
|
49 | 51 | protected function configureEnvironmentSettings(): void |
50 | 52 | { |
51 | | - //@todo configure environment variables inside cachet.php |
| 53 | + $path = text( |
| 54 | + 'Which path do you want Cachet to be accessible from?', |
| 55 | + default: config('cachet.path') |
| 56 | + ); |
| 57 | + |
| 58 | + $title = text( |
| 59 | + 'What will the title of your status page be?', |
| 60 | + default: config('cachet.title') |
| 61 | + ); |
| 62 | + |
| 63 | + $connection = text( |
| 64 | + 'Which database connection do you wish to use for Cachet?', |
| 65 | + default: config('cachet.database_connection') |
| 66 | + ); |
| 67 | + |
| 68 | + $beacon = confirm( |
| 69 | + 'Do you wish to send anonymous data to cachet to help us understand how Cachet is used?', |
| 70 | + default: config('cachet.beacon') |
| 71 | + ); |
| 72 | + |
| 73 | + $this->writeEnv([ |
| 74 | + 'CACHET_PATH' => $path, |
| 75 | + 'CACHET_TITLE' => $title, |
| 76 | + 'CACHET_DB_CONNECTION' => $connection, |
| 77 | + 'CACHET_BEACON' => $beacon, |
| 78 | + ]); |
| 79 | + } |
| 80 | + |
| 81 | + protected function writeEnv(array $values): void |
| 82 | + { |
| 83 | + $environmentFile = app()->environmentFile(); |
| 84 | + $environmentPath = app()->environmentPath(); |
| 85 | + $fullPath = $environmentPath . '/' . $environmentFile; |
| 86 | + |
| 87 | + $envFileContents = File::lines($fullPath)->collect(); |
| 88 | + |
| 89 | + foreach ($values as $key => $value) { |
| 90 | + $existingKey = $envFileContents->search(function ($line) use ($key) { |
| 91 | + return stripos($line, $key) !== false; |
| 92 | + }); |
| 93 | + |
| 94 | + if (Str::contains($value, ' ')) { |
| 95 | + $value = Str::wrap($value,'"'); |
| 96 | + } |
| 97 | + |
| 98 | + if ($value === true) { |
| 99 | + $value = 'true'; |
| 100 | + } |
| 101 | + |
| 102 | + if ($value === false) { |
| 103 | + $value = 'false'; |
| 104 | + } |
| 105 | + |
| 106 | + if ($existingKey === false) { |
| 107 | + $envFileContents->push($key . '=' . $value); |
| 108 | + } else { |
| 109 | + $envFileContents->put($existingKey, $key . '=' . $value); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + File::put($fullPath, $envFileContents->implode("\n")); |
52 | 114 | } |
53 | 115 |
|
54 | 116 | protected function configureDatabaseSettings(AppSettings $settings): AppSettings |
|
0 commit comments