Class JSONConfig - Stefanius67/Config GitHub Wiki

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


Class for config component getting data from JSON file.

Overview

Method Description
__construct The constructor expects an valid filename/path to the JSON file.
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.

Methods

__construct

The constructor expects an valid filename/path to the JSON file.

public JSONConfig::__construct(string $strConfigFile)

Parameters:

Parameter Type Description
strConfigFile string

[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** ⚠️