PHP Class Gdn_Configuration, vanilla

Inheritance: extends Gdn_Pluggable
Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Méthodes publiques

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

Protected Properties

Свойство 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?

Méthodes publiques

Méthode 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?

Méthodes protégées

Méthode 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 méthode

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

__destruct() public méthode

public __destruct ( )

autoSave() public méthode

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

caching() public méthode

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

clearCache() public méthode

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

clearSaveData() public méthode

public clearSaveData ( )

defaultPath() public méthode

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.
Résultat string Returns the current default config path.

dynamic() public méthode

Get current dynamic ConfigurationSource
public dynamic ( ) : Gdn_ConfigurationSource
Résultat Gdn_ConfigurationSource

find() public méthode

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.
Résultat mixed A reference to the configuration data node.

format() public static méthode

public static format ( $Data, array $Options = [] ) : string
$Data
$Options array
Résultat string

get() public méthode

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.
Résultat mixed The configuration value.

getSortFlag() public méthode

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

getSource() public méthode

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
Résultat ConfigurationSource

isList() protected static méthode

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

load() public méthode

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.
Résultat boolean

loadArray() public méthode

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.
Résultat boolean

loadFile() public static méthode

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

loadString() public méthode

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.
Résultat boolean

massImport() public méthode

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

mergeConfig() protected static méthode

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

overlayDynamic() public méthode

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 méthode

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.
Résultat boolean Wether or not the key was found.

removeFromConfig() public méthode

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 méthode

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.
Résultat boolean

saveFile() public static méthode

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

saveToConfig() public méthode

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

set() public méthode

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 méthode

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

shutdown() public méthode

public shutdown ( )

splitting() public méthode

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
Résultat 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