Files
opensourcepos/app/Config/OSPOS.php
objecttothis 48c04417b8 Fixes
- PHP 8.2 deprecates dynamically declared class properties. Adding these declarations removes deprecation warnings and makes the code PHP 8.3 compatible.
- Add Elvis operator to set search string to an empty string when it's value is null to get rid of an error in the search function call.
- Imported class for OSPOS config
- Replaced private with protected in parent controller's property.
- Removed unneeded TODO
- Refactored local variables
- Replaced ternary notation
- Removed unneeded comments
- Removed unneeded class property
- Removed unneeded @property declarations
- Fixed database version
2024-06-15 17:19:15 +02:00

54 lines
1.2 KiB
PHP

<?php
namespace Config;
use App\Models\Appconfig;
use CodeIgniter\Cache\CacheInterface;
use CodeIgniter\Config\BaseConfig;
/**
* This class holds the configuration options stored from the database so that on launch those settings can be cached
* once in memory. The settings are referenced frequently, so there is a significant performance hit to not storing
* them.
*/
class OSPOS extends BaseConfig
{
public array $settings;
public string $commit_sha1 = 'dev'; //TODO: Travis scripts need to be updated to replace this with the commit hash on build
private CacheInterface $cache;
public function __construct()
{
parent::__construct();
$this->cache = Services::cache();
$this->set_settings();
}
public function set_settings(): void
{
helper('locale');
$cache = $this->cache->get('settings');
if($cache)
{
$this->settings = decode_array($cache);
}
else
{
$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));
}
}
public function update_settings(): void
{
$this->cache->delete('settings');
$this->set_settings();
}
}