Class ArrayConfig - Stefanius67/Config GitHub Wiki

Full name:     \SKien\Config\ArrayConfig
Parent class:    \SKien\Config\AbstractConfig


Class for config component getting data directly from Array.

Overview

Method Description
__construct The array containing configuartion data can directly be passed to the constructor.
addConfig Add additional data to the current config.
getArray Get the array specified by path.
getBool Get the boolean value specified by path.
getConfig Returns the internal array.
getDate Get the date value specified by path.
getDateTime Get the date and time value specified by path as unix timestamp.
getFloat Get the float value specified by path.
getInt Get the integer value specified by path.
getString Get the string value specified by path.
getValue Get the value specified by path.
mergeWith Merge this instance with values from onather config.
setDateFormat Set the format for date parameters.
setDateTimeFormat Set the format for datetime parameters.
setPathSeparator Set the separator character.
setValue Add new value to the config.

Methods

__construct

The array containing configuartion data can directly be passed to the constructor.

public ArrayConfig::__construct(array $aConfig = [])

Additional data can be passed with the setValue() and addConfig() methods.

Parameters:

Parameter Type Description
aConfig array associative array

[go to top]


addConfig

Add additional data to the current config.

public ArrayConfig::addConfig(array $aConfig) : void

Note: This method uses the php array_merge() function!
If the additional data contains section(s) the current config at least contains, the complete section is overwritten!
If you want to 'realy' merge two configurations, you have to use separate instances and use the mergeWith() method!

Parameters:

Parameter Type Description
aConfig array associative array

[go to top]


setValue

Add new value to the config.

public ArrayConfig::setValue(string $strName, mixed $value) : void

Currently only values of highest level are supported.

Parameters:

Parameter Type Description
strName string name of the value to set
value mixed value to set

[go to top]


Inherited methods

getArray

Get the array specified by path.

public AbstractConfig::getArray(string $strPath, array $aDefault = []) : array

Parameters:

Parameter Type Description
strPath string
aDefault array

Return Type: array

[go to top]


getBool

Get the boolean value specified by path.

public AbstractConfig::getBool(string $strPath, bool $bDefault = false) : bool

Parameters:

Parameter Type Description
strPath string
bDefault bool

Return Type: bool

[go to top]


getConfig

Returns the internal array.

public AbstractConfig::getConfig() : array

Return Type: array

[go to top]


getDate

Get the date value specified by path.

public AbstractConfig::getDate(string $strPath, int $default) : int

If the config file contains an integer, it is seen as unix timestamp. If the config file contains the date as string, it is parsed with the internal date format set by setDateFormat() (default: 'Y-m-d')

Parameters:

Parameter Type Description
strPath string
default int default value (unix timestamp)

Return Type: int

date as unix timestamp

[go to top]


getDateTime

Get the date and time value specified by path as unix timestamp.

public AbstractConfig::getDateTime(string $strPath, int $default) : int

If the config file contains an integer, it is seen as unix timestamp. If the config file contains the date-time as string, it is parsed with the internal date format set by setDateTimeFormat() (default: 'Y-m-d H:i')

Parameters:

Parameter Type Description
strPath string
default int default value (unix timestamp)

Return Type: int

unix timestamp

[go to top]


getFloat

Get the float value specified by path.

public AbstractConfig::getFloat(string $strPath, float $fltDefault = 0.0) : float

Parameters:

Parameter Type Description
strPath string
fltDefault float

Return Type: float

[go to top]


getInt

Get the integer value specified by path.

public AbstractConfig::getInt(string $strPath, int $iDefault) : int

Parameters:

Parameter Type Description
strPath string
iDefault int

Return Type: int

[go to top]


getString

Get the string value specified by path.

public AbstractConfig::getString(string $strPath, string $strDefault = '') : string

Parameters:

Parameter Type Description
strPath string
strDefault string

Return Type: string

[go to top]


getValue

Get the value specified by path.

public AbstractConfig::getValue(string $strPath, mixed $default = null) : mixed

The path addresses a value within the configuration, which can be nested at any depth (depending on the file format). The individual levels are specified separated by a separator (default is '.'). The separator can be changed with setPathSeparator ().

Parameters:

Parameter Type Description
strPath string the path to the value.
default mixed a default value that is returned if entry doesn't exist

Return Type: mixed

See Also:

[go to top]


mergeWith

Merge this instance with values from onather config.

public AbstractConfig::mergeWith(\SKien\Config\AbstractConfig $oMerge) : void

Note that the elemenst of the config to merge with has allways higher priority than the elements of this instance.
If both config contains elements with the same key, the value of this instance will be replaced with the value of the config we merge with.
So keep allways the order in wich you merge several configs together in mind.

Parameters:

Parameter Type Description
oMerge \SKien\Config\AbstractConfig

[go to top]


setDateFormat

Set the format for date parameters.

public AbstractConfig::setDateFormat(string $strFormat) : void

See the formatting options DateTime::createFromFormat. In most cases, the same letters as for the date() can be used.

Parameters:

Parameter Type Description
strFormat string

See Also:

[go to top]


setDateTimeFormat

Set the format for datetime parameters.

public AbstractConfig::setDateTimeFormat(string $strFormat) : void

See the formatting options DateTime::createFromFormat. In most cases, the same letters as for the date() can be used.

Parameters:

Parameter Type Description
strFormat string

See Also:

[go to top]


setPathSeparator

Set the separator character.

public AbstractConfig::setPathSeparator(string $strSeparator) : void

Default the '.' is used as separator.

Parameters:

Parameter Type Description
strSeparator string

[go to top]


⚠️ **GitHub.com Fallback** ⚠️