diff --git a/app/Filament/Admin/Pages/Settings.php b/app/Filament/Admin/Pages/Settings.php index 17c22f9e3..d8b0183f0 100644 --- a/app/Filament/Admin/Pages/Settings.php +++ b/app/Filament/Admin/Pages/Settings.php @@ -630,7 +630,6 @@ class Settings extends Page implements HasForms ->onColor('success') ->offColor('danger') ->live() - ->columnSpanFull() ->formatStateUsing(fn ($state): bool => (bool) $state) ->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_SEND_INSTALL_NOTIFICATION', (bool) $state)) ->default(env('PANEL_SEND_INSTALL_NOTIFICATION', config('panel.email.send_install_notification'))), @@ -641,7 +640,6 @@ class Settings extends Page implements HasForms ->onColor('success') ->offColor('danger') ->live() - ->columnSpanFull() ->formatStateUsing(fn ($state): bool => (bool) $state) ->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_SEND_REINSTALL_NOTIFICATION', (bool) $state)) ->default(env('PANEL_SEND_REINSTALL_NOTIFICATION', config('panel.email.send_reinstall_notification'))), diff --git a/app/Traits/EnvironmentWriterTrait.php b/app/Traits/EnvironmentWriterTrait.php index 20a0c1680..5df4cdb1d 100644 --- a/app/Traits/EnvironmentWriterTrait.php +++ b/app/Traits/EnvironmentWriterTrait.php @@ -2,54 +2,20 @@ namespace App\Traits; -use Exception; +use Illuminate\Support\Env; +use RuntimeException; trait EnvironmentWriterTrait { - /** - * Escapes an environment value by looking for any characters that could - * reasonably cause environment parsing issues. Those values are then wrapped - * in quotes before being returned. - */ - public function escapeEnvironmentValue(string $value): string - { - if (!preg_match('/^\"(.*)\"$/', $value) && preg_match('/([^\w.\-+\/])+/', $value)) { - return sprintf('"%s"', addcslashes($value, '\\"')); - } - - return $value; - } - /** * Update the .env file for the application using the passed in values. * * @param array $values * - * @throws Exception + * @throws RuntimeException */ public function writeToEnvironment(array $values = []): void { - $path = base_path('.env'); - if (!file_exists($path)) { - throw new Exception('Cannot locate .env file, was this software installed correctly?'); - } - - $saveContents = file_get_contents($path); - if ($saveContents === false) { - $saveContents = ''; - } - - collect($values)->each(function ($value, $key) use (&$saveContents) { - $key = strtoupper($key); - $saveValue = sprintf('%s=%s', $key, $this->escapeEnvironmentValue($value ?? '')); - - if (preg_match_all('/^' . $key . '=(.*)$/m', $saveContents) < 1) { - $saveContents = $saveContents . PHP_EOL . $saveValue; - } else { - $saveContents = preg_replace('/^' . $key . '=(.*)$/m', $saveValue, $saveContents); - } - }); - - file_put_contents($path, $saveContents); + Env::writeVariables($values, base_path('.env'), true); } } diff --git a/tests/Unit/Helpers/EnvironmentWriterTraitTest.php b/tests/Unit/Helpers/EnvironmentWriterTraitTest.php deleted file mode 100644 index 4678c0579..000000000 --- a/tests/Unit/Helpers/EnvironmentWriterTraitTest.php +++ /dev/null @@ -1,43 +0,0 @@ -escapeEnvironmentValue($input); - - $this->assertSame($expected, $output); - } - - public static function variableDataProvider(): array - { - return [ - ['foo', 'foo'], - ['abc123', 'abc123'], - ['val"ue', '"val\"ue"'], - ['val\'ue', '"val\'ue"'], - ['my test value', '"my test value"'], - ['mysql_p@assword', '"mysql_p@assword"'], - ['mysql_p#assword', '"mysql_p#assword"'], - ['mysql p@$$word', '"mysql p@$$word"'], - ['mysql p%word', '"mysql p%word"'], - ['mysql p#word', '"mysql p#word"'], - ['abc_@#test', '"abc_@#test"'], - ['test 123 $$$', '"test 123 $$$"'], - ['#password%', '"#password%"'], - ['$pass ', '"$pass "'], - ]; - } -} - -class FooClass -{ - use EnvironmentWriterTrait; -}