Fix LocString serialization

.. just implement __serialize, d'uh!
This commit is contained in:
Sarjuuk
2025-07-26 23:12:06 +02:00
parent 06bd7aa665
commit 0562989196

View File

@@ -29,11 +29,33 @@ class LocString
return $str; return $str;
foreach (Locale::cases() as $l) // desired loc not set, use any other foreach (Locale::cases() as $l) // desired loc not set, use any other
if ($str = $this->store[$l]) if (isset($this->store[$l]))
return Cfg::get('DEBUG') ? '['.$str.']' : $str; return Cfg::get('DEBUG') ? '['.$this->store[$l].']' : $this->store[$l];
return Cfg::get('DEBUG') ? '[LOCSTRING]' : ''; return Cfg::get('DEBUG') ? '[LOCSTRING]' : '';
} }
public function __serialize(): array
{
$data = [];
foreach (Locale::cases() as $l)
if (isset($this->store[$l]))
$data[$l->value] = $this->store[$l];
return ['store' => $data];
}
public function __unserialize(array $data): void
{
$this->store = new \WeakMap();
if (empty($data['store']))
return;
foreach ($data['store'] as $locId => $str)
if (($l = Locale::tryFrom($locId))?->validate())
$this->store[$l] = (string)$str;
}
} }
?> ?>