Skip to content
Snippets Groups Projects
Commit 00715dec authored by jurgenhaas's avatar jurgenhaas
Browse files

Allow overwrite of a value in the .env file

parent 57e63c30
No related branches found
No related tags found
No related merge requests found
......@@ -92,14 +92,19 @@ final class Dotenv {
* @param string $value
* The value of the environment variable.
*/
public function put($key, $value) {
public function put($key, $value, $overwrite = FALSE) {
$envContent = file_exists('.env') ? file_get_contents('.env') : '';
$data = $this->dotenv->parse($envContent);
$key = strtoupper($key);
if (!empty(getenv($key))) {
if (!$overwrite && isset($data[$key])) {
return;
}
$env = file_exists('.env') ? file_get_contents('.env') : '';
$env .= PHP_EOL . $key . '=' . $value . PHP_EOL;
file_put_contents('.env', $env);
$data[$key] = $value;
$envContent = '';
foreach ($data as $key => $value) {
$envContent .= $key . '=' . $value . PHP_EOL;
}
file_put_contents('.env', $envContent);
$this->load();
passthru(escapeshellcmd('git -c "user.email=dotenv@lakedrops.com" ignore .env'));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment