FEATURE: change directory structure
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
use App\Models\Settings as SettingsModel;
|
||||
|
||||
/**
|
||||
* Class Settings
|
||||
*
|
||||
* Helper class for easier obtaining system settings
|
||||
*
|
||||
* @package App\CMS\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;
|
||||
self::$initialized = true;
|
||||
return self::$settings->$key;
|
||||
}
|
||||
|
||||
$exists = false;
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for obtaining settings saved as JSON
|
||||
*
|
||||
* @param $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getJson($key)
|
||||
{
|
||||
return json_decode(self::get($key, '{}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user