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

Always store received env variables in .env file

Optimize code
parent 00715dec
No related branches found
Tags 1.0.0
No related merge requests found
......@@ -72,11 +72,12 @@ final class Dotenv {
if ($this->io->isInteractive()) {
$value = $this->io->ask($prompt . ': ');
}
/** @noinspection NotOptimalIfConditionsInspection */
if (empty($value)) {
$value = $default;
}
$this->put($key, $value);
}
$this->put($key, $value);
return $value;
}
......@@ -91,6 +92,7 @@ final class Dotenv {
* The name of the environment variable.
* @param string $value
* The value of the environment variable.
* @param bool $overwrite
*/
public function put($key, $value, $overwrite = FALSE) {
$envContent = file_exists('.env') ? file_get_contents('.env') : '';
......@@ -101,8 +103,8 @@ final class Dotenv {
}
$data[$key] = $value;
$envContent = '';
foreach ($data as $key => $value) {
$envContent .= $key . '=' . $value . PHP_EOL;
foreach ($data as $k => $v) {
$envContent .= $k . '=' . $v . PHP_EOL;
}
file_put_contents('.env', $envContent);
$this->load();
......@@ -132,6 +134,7 @@ final class Dotenv {
* @param string $key
*/
private function findEnvironmentVariables(&$item, &$key) {
/** @noinspection NotOptimalRegularExpressionsInspection */
$pattern = '@\{\$env:([A-Za-z0-9_]*)\}@i';
preg_match_all($pattern, $item, $item_matches);
preg_match_all($pattern, $key, $key_matches);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment