1
0

Remove a metadata file if empty when saving

This commit is contained in:
Richard Dern 2024-04-24 23:28:33 +02:00
parent 7d2ada5e86
commit c82ed9dbf3

View File

@ -65,11 +65,15 @@ public function isDirty(): bool
*/ */
public function save(): bool public function save(): bool
{ {
if (!$this->isDirty() || empty($this->content)) { if (!$this->isDirty()) {
return false; return false;
} }
$this->writeToDisk($this->content); if (empty($this->content)) {
$this->disk->delete($this->filename);
} else {
$this->writeToDisk($this->content);
}
$this->originalContent = $this->content; $this->originalContent = $this->content;
@ -94,10 +98,14 @@ public function set($key, $value, bool $respectDots = true)
/** /**
* Set many values at once * Set many values at once
*/ */
public function setMany(array $array) public function setMany(array $array, bool $replace = false)
{ {
foreach ($array as $key => $value) { if (!$replace) {
$this->set($key, $value); foreach ($array as $key => $value) {
$this->set($key, $value);
}
} else {
$this->content = $array;
} }
} }