70 lines
1.3 KiB
PHP
70 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use App\Models\Settings as SettingsModel;
|
|
|
|
/**
|
|
* Class Settings
|
|
*
|
|
* Helper class for easier obtaining system settings
|
|
*
|
|
* @package App\Helpers
|
|
*/
|
|
class Settings
|
|
{
|
|
/**
|
|
* @var array List of all used settings
|
|
*/
|
|
protected static $settings;
|
|
/**
|
|
* @var bool Are data already initialized?
|
|
*/
|
|
protected static $initialized = false;
|
|
|
|
/**
|
|
* Getter for settings determined with key.
|
|
*
|
|
* @param string $key settings key
|
|
* @param string|null $default default value, which will be returned when given key does not exist
|
|
*
|
|
* @param null $exists
|
|
*
|
|
* @return null|string
|
|
*/
|
|
public static function get($key, $default = null, & $exists = null)
|
|
{
|
|
self::init();
|
|
|
|
if (isset(self::$settings->$key)) {
|
|
$exists = true;
|
|
return self::$settings->$key;
|
|
}
|
|
|
|
$exists = false;
|
|
return $default;
|
|
}
|
|
|
|
/**
|
|
* Get all settings
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function all()
|
|
{
|
|
self::init();
|
|
|
|
return self::$settings;
|
|
}
|
|
|
|
/**
|
|
* Initialize settings array
|
|
*/
|
|
private static function init()
|
|
{
|
|
if (!self::$initialized) {
|
|
$model = new SettingsModel();
|
|
self::$settings = $model->getAll();
|
|
}
|
|
}
|
|
} |