PHP Class Gdn_Configuration, vanilla

Inheritance: extends Gdn_Pluggable
Exibir arquivo Open project: vanilla/vanilla Class Usage Examples

Public Properties

Property Type Description
$Data Holds the associative array of configuration data. ie. $this->_Data['Group0']['Group1']['ConfigurationName'] = 'Value';
$NotFound string

Protected Properties

Property Type Description
$autoSave Whether or not to autosave this config when it is destructed.
$defaultGroup The default top level group for new configs.
$defaultPath The path to the default configuration file.
$dynamic Dynamic (writable) config source. This is the configuration source that is written to when saves or removes are occurring.
$sources Configuration Source List Associative array of Gdn_ConfigurationSource objects indexed by their respective types and source URIs. E.g: file:/path/to/config/file.php => ... string:tagname => ...
$splitting Allow dot-delimited splitting?
$useCaching Use caching to load and save configs?

Public Methods

Method Description
__construct ( string $DefaultGroup = null ) Initialize a new instance of the {@link Gdn_Configuration} class.
__destruct ( )
autoSave ( boolean $AutoSave = true )
caching ( boolean $Caching = null ) : boolean Use caching when loading/saving configs.
clearCache ( string $ConfigFile ) : void Clear cache entry for this config file.
clearSaveData ( )
defaultPath ( string $Value = null ) : string Gets or sets the path of the default configuration file.
dynamic ( ) : Gdn_ConfigurationSource Get current dynamic ConfigurationSource
find ( string $Name, boolean $Create = true ) : mixed Finds the data at a given position and returns a reference to it.
format ( $Data, array $Options = [] ) : string
get ( string $Name, mixed $DefaultValue = false ) : mixed Gets a setting from the configuration array. Returns $DefaultValue if the value isn't found.
getSortFlag ( ) : null | integer
getSource ( string $Type, string $Identifier ) : ConfigurationSource Get a reference to the internal ConfigurationSource for a given type and ID
load ( string $File, string $Name = 'Configuration', boolean $Dynamic = false ) : boolean Loads an array of settings from a file into the object with the specified name;
loadArray ( string $ConfigData, string $Tag, string $Name = 'Configuration', boolean $Dynamic = true, $SaveCallback = null, $CallbackOptions = null ) : boolean Loads settings from an array into the object with the specified name;
loadFile ( $Path, $Options = [] ) DO NOT USE, THIS IS RUBBISH
loadString ( string $String, string $Tag, string $Name = 'Configuration', boolean $Dynamic = true, $SaveCallback = null, $CallbackOptions = null ) : boolean Loads settings from a string into the object with the specified name;
massImport ( type $Data ) Import a large pre-formatted set of configs efficiently
overlayDynamic ( ) Re-apply the settings from the current dynamic config source
remove ( string $Name, $Save = true ) : boolean Removes the specified key from the specified group (if it exists).
removeFromConfig ( string | array $Name, boolean | array $Options = [] ) Remove key (or keys) from config
save ( string $File = null, string $Group = null ) : boolean Saves all settings in $Group to $File.
saveFile ( $Path, $Data, array $Options = [] )
saveToConfig ( $Name, string $Value = '', array $Options = [] ) : boolean | integer
set ( string $Name, mixed $Value, boolean $Overwrite = true, $Save = true ) Assigns a setting to the configuration array.
setSortFlag ( integer $sortFlag ) : Gdn_Configuration Set the sort flag to be used with ksort.
shutdown ( )
splitting ( boolean $Splitting = true ) Allow dot-delimited splitting on keys?

Protected Methods

Method Description
isList ( array &$list ) : boolean Determine if a given array is a list (or a hash)
mergeConfig ( array &$Data, array $Loaded ) Merge a newly loaded config into the current active state

Method Details

__construct() public method

Initialize a new instance of the {@link Gdn_Configuration} class.
public __construct ( string $DefaultGroup = null )
$DefaultGroup string

__destruct() public method

public __destruct ( )

autoSave() public method

public autoSave ( boolean $AutoSave = true )
$AutoSave boolean

caching() public method

Use caching when loading/saving configs.
public caching ( boolean $Caching = null ) : boolean
$Caching boolean Whether to use caching.
return boolean

clearCache() public method

Clear cache entry for this config file.
public clearCache ( string $ConfigFile ) : void
$ConfigFile string
return void

clearSaveData() public method

public clearSaveData ( )

defaultPath() public method

Gets or sets the path of the default configuration file.
Since: 2.3
public defaultPath ( string $Value = null ) : string
$Value string Pass a value to set a new default config path.
return string Returns the current default config path.

dynamic() public method

Get current dynamic ConfigurationSource
public dynamic ( ) : Gdn_ConfigurationSource
return Gdn_ConfigurationSource

find() public method

Finds the data at a given position and returns a reference to it.
public find ( string $Name, boolean $Create = true ) : mixed
$Name string The name of the configuration using dot notation.
$Create boolean Whether or not to create the data if it isn't there already.
return mixed A reference to the configuration data node.

format() public static method

public static format ( $Data, array $Options = [] ) : string
$Data
$Options array
return string

get() public method

Gets a setting from the configuration array. Returns $DefaultValue if the value isn't found.
public get ( string $Name, mixed $DefaultValue = false ) : mixed
$Name string The name of the configuration setting to get. If the setting is contained within an associative array, use dot denomination to get the setting. ie. $this->Get('Database.Host') would retrieve $Configuration[$Group]['Database']['Host'].
$DefaultValue mixed If the parameter is not found in the group, this value will be returned.
return mixed The configuration value.

getSortFlag() public method

public getSortFlag ( ) : null | integer
return null | integer The sort flag to be used with ksort.

getSource() public method

Get a reference to the internal ConfigurationSource for a given type and ID
public getSource ( string $Type, string $Identifier ) : ConfigurationSource
$Type string 'file' or 'string'
$Identifier string filename or string tag
return ConfigurationSource

isList() protected static method

Determine if a given array is a list (or a hash)
protected static isList ( array &$list ) : boolean
$list array
return boolean

load() public method

Loads an array of settings from a file into the object with the specified name;
public load ( string $File, string $Name = 'Configuration', boolean $Dynamic = false ) : boolean
$File string A string containing the path to a file that contains the settings array.
$Name string The name of the variable and initial group settings. Note: When $Name is 'Configuration' then the data will be set to the root of the config.
$Dynamic boolean Optional, whether to treat this as the request's "dynamic" config, and to save config changes here. These settings will also be re-applied later when "OverlayDynamic" is called after all defaults are loaded.
return boolean

loadArray() public method

This array should be a hierarchical Vanilla config.
public loadArray ( string $ConfigData, string $Tag, string $Name = 'Configuration', boolean $Dynamic = true, $SaveCallback = null, $CallbackOptions = null ) : boolean
$ConfigData string An array containing the configuration data
$Tag string A string descriptor of this config set
$Name string The name of the variable and initial group settings. Note: When $Name is 'Configuration' then the data will be set to the root of the config.
$Dynamic boolean Optional, whether to treat this as the request's "dynamic" config, and to save config changes here. These settings will also be re-applied later when "OverlayDynamic" is called after all defaults are loaded.
return boolean

loadFile() public static method

DO NOT USE, THIS IS RUBBISH
Deprecation:
public static loadFile ( $Path, $Options = [] )

loadString() public method

This string should be a textual representation of a PHP config array, ready to be eval()'d.
public loadString ( string $String, string $Tag, string $Name = 'Configuration', boolean $Dynamic = true, $SaveCallback = null, $CallbackOptions = null ) : boolean
$String string A string containing the php settings array.
$Tag string A string descriptor of this config set
$Name string The name of the variable and initial group settings. Note: When $Name is 'Configuration' then the data will be set to the root of the config.
$Dynamic boolean Optional, whether to treat this as the request's "dynamic" config, and to save config changes here. These settings will also be re-applied later when "OverlayDynamic" is called after all defaults are loaded.
return boolean

massImport() public method

NOTE: ONLY WORKS WHEN SPLITTING IS OFF!
public massImport ( type $Data )
$Data type

mergeConfig() protected static method

Recursively
protected static mergeConfig ( array &$Data, array $Loaded )
$Data array Reference to the current active state
$Loaded array Data to merge

overlayDynamic() public method

It may be necessary to load some default configs after loading the client config. These defaults may be overridden in the client's initial config, so that will need to be re-applied once the correct defaults are included. This method does that
public overlayDynamic ( )

remove() public method

Returns false if the key is not found for removal, true otherwise.
public remove ( string $Name, $Save = true ) : boolean
$Name string The name of the configuration setting with dot notation.
return boolean Wether or not the key was found.

removeFromConfig() public method

Remove key (or keys) from config
public removeFromConfig ( string | array $Name, boolean | array $Options = [] )
$Name string | array Key name, or assoc array of keys to unset
$Options boolean | array Bool = whether to save or not. Assoc array = Save => Whether to save or not

save() public method

Saves all settings in $Group to $File.
public save ( string $File = null, string $Group = null ) : boolean
$File string The full path to the file where the Settings should be saved.
$Group string The name of the settings group to be saved to the $File.
return boolean

saveFile() public static method

public static saveFile ( $Path, $Data, array $Options = [] )
$Path
$Data
$Options array

saveToConfig() public method

public saveToConfig ( $Name, string $Value = '', array $Options = [] ) : boolean | integer
$Name
$Value string
$Options array
return boolean | integer

set() public method

Assigns a setting to the configuration array.
public set ( string $Name, mixed $Value, boolean $Overwrite = true, $Save = true )
$Name string The name of the configuration setting to assign. If the setting is contained within an associative array, use dot denomination to get the setting. ie. $this->Set('Database.Host', $Value) would set $Configuration[$Group]['Database']['Host'] = $Value
$Value mixed The value of the configuration setting.
$Overwrite boolean If the setting already exists, should it's value be overwritten? Defaults to true.

setSortFlag() public method

Set the sort flag to be used with ksort.
public setSortFlag ( integer $sortFlag ) : Gdn_Configuration
$sortFlag integer As defined in php standard definitions
return Gdn_Configuration $this

shutdown() public method

public shutdown ( )

splitting() public method

Allow dot-delimited splitting on keys?
public splitting ( boolean $Splitting = true )
$Splitting boolean

Property Details

$Data public_oe property

Holds the associative array of configuration data. ie. $this->_Data['Group0']['Group1']['ConfigurationName'] = 'Value';
public $Data

$NotFound public_oe property

public string $NotFound
return string

$autoSave protected_oe property

Whether or not to autosave this config when it is destructed.
protected $autoSave

$defaultGroup protected_oe property

The default top level group for new configs.
protected $defaultGroup

$defaultPath protected_oe property

The path to the default configuration file.
protected $defaultPath

$dynamic protected_oe property

Dynamic (writable) config source. This is the configuration source that is written to when saves or removes are occurring.
protected $dynamic

$sources protected_oe property

Configuration Source List Associative array of Gdn_ConfigurationSource objects indexed by their respective types and source URIs. E.g: file:/path/to/config/file.php => ... string:tagname => ...
protected $sources

$splitting protected_oe property

Allow dot-delimited splitting?
protected $splitting

$useCaching protected_oe property

Use caching to load and save configs?
protected $useCaching