From 056298919607b73bd82835806ab4607b08cc0e7f Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sat, 26 Jul 2025 23:12:06 +0200 Subject: [PATCH] Fix LocString serialization .. just implement __serialize, d'uh! --- includes/components/locstring.class.php | 26 +++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/includes/components/locstring.class.php b/includes/components/locstring.class.php index 90408532..646c1fd4 100644 --- a/includes/components/locstring.class.php +++ b/includes/components/locstring.class.php @@ -29,11 +29,33 @@ class LocString return $str; foreach (Locale::cases() as $l) // desired loc not set, use any other - if ($str = $this->store[$l]) - return Cfg::get('DEBUG') ? '['.$str.']' : $str; + if (isset($this->store[$l])) + return Cfg::get('DEBUG') ? '['.$this->store[$l].']' : $this->store[$l]; 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; + } } ?>