fix
This commit is contained in:
parent
8833a2c605
commit
996d201575
|
@ -33,8 +33,24 @@ class PutEnv {
|
|||
if (!file_exists($this->file)) {
|
||||
throw new Exception('File not found');
|
||||
}
|
||||
$changed = 0;
|
||||
$lineWasEmpty = false;
|
||||
$key = $this->key;
|
||||
$value = $this->value;
|
||||
if (strpos($value, ' ') !== false) {
|
||||
$value = '"' . addslashes($value) . '"';
|
||||
}
|
||||
$this->content = file($this->file);
|
||||
foreach ($this->content as $l => $line) {
|
||||
if (strlen($line) < 1) {
|
||||
if ($lineWasEmpty) {
|
||||
unset ($this->content[$l]);
|
||||
} else {
|
||||
$lineWasEmpty = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$lineWasEmpty = false;
|
||||
if (!str_starts_with($line, $this->key)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -42,12 +58,13 @@ class PutEnv {
|
|||
if (strlen($next) === 0 || $next[0] !== '=') {
|
||||
continue;
|
||||
}
|
||||
$key = $this->key;
|
||||
$value = $this->value;
|
||||
if (strpos($value, ' ') !== false) {
|
||||
$value = '"' . addslashes($value) . '"';
|
||||
}
|
||||
$this->content[$l] = $key . '=' . $value;
|
||||
$changed++;
|
||||
}
|
||||
if ($changed === 0) {
|
||||
$this->content[] = $key . '=' . $value;
|
||||
} else if ($changed > 1) {
|
||||
echo "Key $key changed $changed times\n";
|
||||
}
|
||||
$content = implode("\n", $this->content);
|
||||
file_put_contents($this->file, $content);
|
||||
|
|
Loading…
Reference in New Issue