Class ArrayConfig - Stefanius67/Config GitHub Wiki
Full name: \SKien\Config\ArrayConfig
Parent class: \SKien\Config\AbstractConfig
| 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. |
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 |
Add additional data to the current config.
public ArrayConfig::addConfig(array $aConfig) : voidNote: 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 |
Add new value to the config.
public ArrayConfig::setValue(string $strName, mixed $value) : voidCurrently only values of highest level are supported.
Parameters:
| Parameter | Type | Description |
|---|---|---|
strName |
string | name of the value to set |
value |
mixed | value to set |
Get the array specified by path.
public AbstractConfig::getArray(string $strPath, array $aDefault = []) : arrayParameters:
| Parameter | Type | Description |
|---|---|---|
strPath |
string | |
aDefault |
array |
Return Type: array
Get the boolean value specified by path.
public AbstractConfig::getBool(string $strPath, bool $bDefault = false) : boolParameters:
| Parameter | Type | Description |
|---|---|---|
strPath |
string | |
bDefault |
bool |
Return Type: bool
Returns the internal array.
public AbstractConfig::getConfig() : arrayReturn Type: array
Get the date value specified by path.
public AbstractConfig::getDate(string $strPath, int $default) : intIf 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
Get the date and time value specified by path as unix timestamp.
public AbstractConfig::getDateTime(string $strPath, int $default) : intIf 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
Get the float value specified by path.
public AbstractConfig::getFloat(string $strPath, float $fltDefault = 0.0) : floatParameters:
| Parameter | Type | Description |
|---|---|---|
strPath |
string | |
fltDefault |
float |
Return Type: float
Get the integer value specified by path.
public AbstractConfig::getInt(string $strPath, int $iDefault) : intParameters:
| Parameter | Type | Description |
|---|---|---|
strPath |
string | |
iDefault |
int |
Return Type: int
Get the string value specified by path.
public AbstractConfig::getString(string $strPath, string $strDefault = '') : stringParameters:
| Parameter | Type | Description |
|---|---|---|
strPath |
string | |
strDefault |
string |
Return Type: string
Get the value specified by path.
public AbstractConfig::getValue(string $strPath, mixed $default = null) : mixedThe 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:
Merge this instance with values from onather config.
public AbstractConfig::mergeWith(\SKien\Config\AbstractConfig $oMerge) : voidNote 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 |
Set the format for date parameters.
public AbstractConfig::setDateFormat(string $strFormat) : voidSee 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:
Set the format for datetime parameters.
public AbstractConfig::setDateTimeFormat(string $strFormat) : voidSee 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:
Set the separator character.
public AbstractConfig::setPathSeparator(string $strSeparator) : voidDefault the '.' is used as separator.
Parameters:
| Parameter | Type | Description |
|---|---|---|
strSeparator |
string |