62 lines
1.2 KiB
PHP
62 lines
1.2 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
|
|
*
|
|
* @return string|null
|
|
*/
|
|
public static function get($key, $default = null)
|
|
{
|
|
self::init();
|
|
|
|
return isset(self::$settings->$key) ? self::$settings->$key : $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();
|
|
}
|
|
}
|
|
} |