Skip to content

Commit

Permalink
Merge pull request #3342 from nstapelbroek/feature/explicit-port-numbers
Browse files Browse the repository at this point in the history
Write port numbers explicitly to the .env
  • Loading branch information
jbrooksuk committed Dec 27, 2018
2 parents 84fd584 + 3d632a4 commit a01d7d4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ protected function configureDatabase(array $default = [])

$config['DB_PASSWORD'] = $this->secret('What password should we connect with?', $config['DB_PASSWORD']);

$config['DB_PORT'] = $config['DB_DRIVER'] === 'mysql' ? 3306 : 5432;
if ($this->confirm('Is your database listening on a non-standard port number?')) {
$config['DB_PORT'] = $this->anticipate('What port number is your database using?', [3306, 5432], $config['DB_PORT']);
}
Expand Down Expand Up @@ -391,11 +392,12 @@ protected function writeEnv($key, $value)
$envKey = strtoupper($key);
$envValue = env($envKey) ?: 'null';

file_put_contents($path, str_replace(
"{$envKey}={$envValue}",
"{$envKey}={$value}",
file_get_contents($path)
));
$envFileContents = file_get_contents($path);
$envFileContents = str_replace("{$envKey}={$envValue}", "{$envKey}={$value}", $envFileContents, $count);
if ($count < 1 && $envValue === 'null') {
$envFileContents = str_replace("{$envKey}=", "{$envKey}={$value}", $envFileContents);
}
file_put_contents($path, $envFileContents);
} catch (InvalidPathException $e) {
throw $e;
}
Expand Down

0 comments on commit a01d7d4

Please sign in to comment.