PHP Класс Gdn_Configuration, vanilla

Наследование: extends Gdn_Pluggable
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$Data Holds the associative array of configuration data. ie. $this->_Data['Group0']['Group1']['ConfigurationName'] = 'Value';
$NotFound string

Защищенные свойства (Protected)

Свойство Тип Описание
$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?

Открытые методы

Метод Описание
__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?

Защищенные методы

Метод Описание
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

Описание методов

__construct() публичный Метод

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

__destruct() публичный Метод

public __destruct ( )

autoSave() публичный Метод

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

caching() публичный Метод

Use caching when loading/saving configs.
public caching ( boolean $Caching = null ) : boolean
$Caching boolean Whether to use caching.
Результат boolean

clearCache() публичный Метод

Clear cache entry for this config file.
public clearCache ( string $ConfigFile ) : void
$ConfigFile string
Результат void

clearSaveData() публичный Метод

public clearSaveData ( )

defaultPath() публичный Метод

Gets or sets the path of the default configuration file.
С версии: 2.3
public defaultPath ( string $Value = null ) : string
$Value string Pass a value to set a new default config path.
Результат string Returns the current default config path.

dynamic() публичный Метод

Get current dynamic ConfigurationSource
public dynamic ( ) : Gdn_ConfigurationSource
Результат Gdn_ConfigurationSource

find() публичный Метод

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.
Результат mixed A reference to the configuration data node.

format() публичный статический Метод

public static format ( $Data, array $Options = [] ) : string
$Data
$Options array
Результат string

get() публичный Метод

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.
Результат mixed The configuration value.

getSortFlag() публичный Метод

public getSortFlag ( ) : null | integer
Результат null | integer The sort flag to be used with ksort.

getSource() публичный Метод

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
Результат ConfigurationSource

isList() защищенный статический Метод

Determine if a given array is a list (or a hash)
protected static isList ( array &$list ) : boolean
$list array
Результат boolean

load() публичный Метод

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.
Результат boolean

loadArray() публичный Метод

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.
Результат boolean

loadFile() публичный статический Метод

DO NOT USE, THIS IS RUBBISH
Устаревший:
public static loadFile ( $Path, $Options = [] )

loadString() публичный Метод

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.
Результат boolean

massImport() публичный Метод

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

mergeConfig() защищенный статический Метод

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

overlayDynamic() публичный Метод

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() публичный Метод

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.
Результат boolean Wether or not the key was found.

removeFromConfig() публичный Метод

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() публичный Метод

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.
Результат boolean

saveFile() публичный статический Метод

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

saveToConfig() публичный Метод

public saveToConfig ( $Name, string $Value = '', array $Options = [] ) : boolean | integer
$Name
$Value string
$Options array
Результат boolean | integer

set() публичный Метод

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() публичный Метод

Set the sort flag to be used with ksort.
public setSortFlag ( integer $sortFlag ) : Gdn_Configuration
$sortFlag integer As defined in php standard definitions
Результат Gdn_Configuration $this

shutdown() публичный Метод

public shutdown ( )

splitting() публичный Метод

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

Описание свойств

$Data публичное свойство

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

$NotFound публичное свойство

public string $NotFound
Результат string

$autoSave защищенное свойство

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

$defaultGroup защищенное свойство

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

$defaultPath защищенное свойство

The path to the default configuration file.
protected $defaultPath

$dynamic защищенное свойство

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

$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 => ...
protected $sources

$splitting защищенное свойство

Allow dot-delimited splitting?
protected $splitting

$useCaching защищенное свойство

Use caching to load and save configs?
protected $useCaching