New Classes for WBCE CMS,  1.4.1
Documentation for all new Classes in WBCE CMS
Static Public Member Functions | Static Public Attributes
Settings Class Reference

This class handles the management of global settings. More...

Static Public Member Functions

static Set ($name="", $value="", $overwrite=true)
 Sets a global setting. More...
 
static Get ($name, $default=false)
 Fetches a single setting. More...
 
static GetFromDb ($name, $default=false)
 Fetches a single setting from DB. More...
 
static GetPrefix ($prefix, $default=false)
 Fetches all settings whith a certain prefix. More...
 
static Del ($name)
 Deletes single setting. More...
 
static Setup ()
 Method to setup constants and variables. More...
 
static Info ()
 A little method to display all settings in DB. More...
 
static DeSerialize ($value)
 Unserialize arrays abd objects stored as serialized strings. More...
 

Static Public Attributes

static $aSettings =array()
 

Detailed Description

This class handles the management of global settings.

It takes care of getting and setting those and it handles the converion and generation into good old constants.

All setting names may only contain a-z 0-9 and "_"
Core settings are prepended by "wb_". (e.g. wb_maintainance_mode)
Module settings are prepended by module name or maybe by a shortened form of the module name.
(e.g. wysi_my_setting for wysiwyg)

This class Now stores its data values although in its $aSettings array. for cached handling of requests.

Attention
Please keep in mind that WB stores settings only as strings.

All those settings are converted into constants in the init process using Settings::Setup(); So "wb_maintainance_mode" is available as WB_MAINTAINANCE_MODE allover in WBCE CMS.

Some examples:

// create or edit a setting
Settings::Set("wb_new_setting","the value");
// using a setting
if (WB_NEW_SETTING =="the value") echo "Horay";
// there is a get function but this is mostly used internal
$myValue= Settings::Get ("wb_new_setting");
// deleting
Settings::Delete("wb_new_setting");
// if used in modules please prepend (shortened)module name to avoid collisions
Settings::Set("wysi_new_setting","another value");
Attention
Arrays and objects are now automatically serialized and de serialized by the "Get" functions. As constants aren't capable of containing arrays and objects bevore PHP7 constants keep the serialized version whith a !!SARRAY!! or !!SOBJECT!! prefix. But you can use the Settings::DeSerialize() function to de serialize a constant
$aNeededArray = Settings::DeSerialize(WB_MY_ARRAY_SETTING);
Todo:
Extend this class to handle different tables. Maybe by making this a class whith instances and a static facade.

Member Function Documentation

static Set (   $name = "",
  $value = "",
  $overwrite = true 
)
static

Sets a global setting.

The Overwrite attribute has been added for use in upgradescripts where you do not want to overwrite an existing setting. Often you only want to add a setting only if its not already set.

Parameters
string$nameThe settings name.
undefined$valueThe value, only strings/boolean allowed.
boolean$overwriteSet to false to only write if setting does not exist.
Return values
boolean/stringReturns false on success and an error message on failure.
static Get (   $name,
  $default = false 
)
static

Fetches a single setting.

Prefered Way of fetching Data As constants update only on next reload.

Example:

GetFromDb("WB_DEFAULT_LANGUAGE");
// Returns "DE" or whatever language is set.
Parameters
string$nameThe settings name, eg. "wb_new_setting".
undefined$defaultWhatever you like as a returnvalue if the method does not find a matching entry.
Return values
array/undefinedReturns the value of the setting or $Default if nothing is found.
static GetFromDb (   $name,
  $default = false 
)
static

Fetches a single setting from DB.

Used mostly as helper, as all setings converted to constants and stored in settings Class.

Example:

GetFromDb("WB_DEFAULT_THEME");
// Returns "argos_theme" or whatever theme is set.
Parameters
string$nameThe settings name, eg. "wb_new_setting".
undefined$defaultWhatever you like as a returnvalue if the method does not find a matching entry.
Return values
array/undefinedReturns the value of the setting or $Default if nothing is found.
static GetPrefix (   $prefix,
  $default = false 
)
static

Fetches all settings whith a certain prefix.

Prefered Way of fetching Data As constants update only on next reload.

Example:

echo "<pre>";
print_r (Settings::GetPrefix("WB"));
echo "<pre>";
// Returns
Array
(
[WB_VERSION] => 2.8.3
[WB_REVISION] => 1641
[WB_SP] => SP4
[WB_MAINTAINANCE_MODE] =>
[WB_SUPPRESS_OLD_OPF] => 0
...
[WB_DEFAULT_THEME] => argos_theme
}
Parameters
string$nameThe settings name, eg. "wb_new_setting".
string$prefixThe prefix of the setting WB_ , TOPICS_ , MYMODULE_ ,....
undefined$defaultWhatever you like as a returnvalue if the method does not find a matching entry.
Return values
array/undefinedReturns the valuee for this prefix or $Default if nothing is found.
static Del (   $name)
static

Deletes single setting.

Simply removes a setting , nothing more.

Parameters
string$nameThe settings name, eg. "wb_new_setting".
Return values
boolean/stringReturns false on success and an error message on failure.
static Setup ( )
static

Method to setup constants and variables.

This Method is used in /framework/initialize.php to setup all settings as constants. And create the aSettings Array inside the class for faster getting of values.

Return values
boolean/stringReturns false on success and an error message on failure.
static Info ( )
static

A little method to display all settings in DB.

This now calls to the self::$aSettings Array too to see difference between Constant and Variables.

Return values
stringAll recent settings as a simple
seperated list.
static DeSerialize (   $value)
static

Unserialize arrays abd objects stored as serialized strings.

It is used internally and to unserialize arrays and objects stored in constants

Parameters
string$valueThe serialized value
Return values
boolean/stringReturns the unserialized object or array.

Field Documentation

$aSettings =array()
static

The documentation for this class was generated from the following file: