Skip to content

Commit

Permalink
[BUGFIX] updates Companion->writeVariable() to support (existing) com…
Browse files Browse the repository at this point in the history
…ments and empty lines in .env files
  • Loading branch information
EvilBMP committed Nov 3, 2023
1 parent 379ecd6 commit 22b6698
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Companienv/Companion.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,22 @@ private function writeVariable(string $name, string $value)
$reader = (new DotenvReader(new ParserV3()))->load($this->envFileName);
foreach ($reader->entries(true) as $entry) {
if (isset($entry['parsed_data'])) {
$writer->appendSetter(
$entry['parsed_data']['key'],
trim($entry['parsed_data']['value'], '"'),
$entry['parsed_data']['comment'],
$entry['parsed_data']['export']
);
switch ($entry['parsed_data']['type']) {
case 'comment':
$writer->appendComment($entry['parsed_data']['comment']);
break;
case 'empty':
$writer->appendEmpty();
break;
case 'setter':
$writer->appendSetter(
$entry['parsed_data']['key'],
trim($entry['parsed_data']['value'], '"'),
$entry['parsed_data']['comment'],
$entry['parsed_data']['export']
);
break;
}
}
}

Expand Down

0 comments on commit 22b6698

Please sign in to comment.