cache = Services::cache(); $this->set_settings(); } /** * @return void */ public function set_settings(): void { $cache = $this->cache->get('settings'); if ($cache) { $this->settings = decode_array($cache); return; } try { $db = Database::connect(); if (!$db->tableExists('app_config')) { $this->settings = $this->getDefaultSettings(); return; } $appconfig = model(Appconfig::class); foreach ($appconfig->get_all()->getResult() as $app_config) { $this->settings[$app_config->key] = $app_config->value; } $this->cache->save('settings', encode_array($this->settings)); } catch (\Exception $e) { $this->settings = $this->getDefaultSettings(); } } private function getDefaultSettings(): array { return [ 'language' => 'english', 'language_code' => 'en', 'company' => 'Home', 'barcode_type' => 'Code39' ]; } /** * @return void */ public function update_settings(): void { $this->cache->delete('settings'); $this->set_settings(); } }