Zeta Components Manual :: Docs For Class ezcConfiguration
Configuration::ezcConfiguration
Class ezcConfiguration
This class provides persistent platform-independent and format independent application settings.
A typical usage for retrieving the settings in an application:
- {
- $colorFg = $conf->getIntSetting( 'Colors', 'Foreground' );
- }
A typical usage for storing the settings of an application:
- // $conf contains an ezcConfiguration object
- array( 'Host', 'User', 'Password' ),
- array( 'localhost', 'dr', 'eXaMpLe' ) );
The current groups and their settings can be examined with:
- // $conf contains an ezcConfiguration object
- foreach ( $groups as $group )
- {
- foreach ( $settings as $setting )
- {
- print "$group:$setting=$value\n";
- }
- }
Alternatively all settings and their values can be returned in one go:
- // $conf contains an ezcConfiguration object
- foreach ( $settings as $setting => $value )
- {
- print "$setting=$value\n";
- }
Or quering the entire configuration settings with getAllSettings():
- // $conf contains an ezcConfiguration object
- foreach ( $allSettings as $group => $settings )
- {
- foreach ( $settings as $setting => $value )
- {
- print "$group:$setting=$value\n";
- }
- }
Fetching specific settings is done using getSetting() or if you want to ensure that it is a specific type use getBoolSetting(), getIntSetting(), getFloatSetting(), getNumberSetting(), getStringSetting() or getArraySetting(). Fetching multiple values is possible with getSettings().
Removing entries is possible with removeSetting(), removeSettings(), removeGroup() and removeAllSettings().
In addition all entries can queried for existance with hasSetting(), hasSettings() and hasGroup().
Reading and writing is done by the various implemenations of ezcConfigurationReader and ezcConfigurationWriter respectively. They provide access to different configuration formats and storage types, for instance INI files and database storage.
If the application does not need to have such finegrained control over the settings the ezcConfigurationManager class might be of interest.
Source for this file: /Configuration/src/configuration.php
Version: | //autogen// |
Method Summary
public ezcConfiguration |
__construct(
[ $settings
= array()] , [ $comments
= array()] )
Constructs the configuration object. |
public void |
addGroup(
$group
, [ $comment
= null] )
Adds a the group $group with the comment $comment the settings. |
public array(array) |
getAllComments(
)
Returns all the groups and their settings comments as an array. |
public array(array) |
getAllSettings(
)
Returns all the groups and their settings and values. |
public array |
getArraySetting(
$group
, $setting
)
Returns the value of the setting $setting in group $group. |
public bool |
getBoolSetting(
$group
, $setting
)
Returns the value of the setting $setting in group $group. |
public string |
getComment(
$group
, $setting
)
Returns the comment belonging to setting $setting located in group $group. |
public array |
getComments(
$group
, $settings
)
Returns the comments belonging to the specified settings $settings as an array. |
public array |
getGroupNames(
)
Returns the names of all the groups as an array. |
public mixed |
getNumberSetting(
$group
, $setting
)
Returns the value of the setting $setting in group $group. |
public mixed |
getSetting(
$group
, $setting
)
Returns the value of setting $setting located in group $group. |
public array(string) |
getSettingNames(
$group
)
Returns the names of all settings in the group $group. |
public array |
getSettings(
$group
, $settings
)
Returns the values of the settings $settings in group $group as an array. |
public array(string=>mixed) |
getSettingsInGroup(
$group
)
Returns all settings in the group $group. |
public string |
getStringSetting(
$group
, $setting
)
Returns the value of the setting $setting in group $group. |
public bool |
hasGroup(
$group
)
Returns true if the group $group exists. |
public bool |
hasSetting(
$group
, $setting
)
Returns true if setting $setting exists within the group $group. |
public bool |
hasSettings(
$group
, $settings
)
Returns true if all the specified settings $settings exists within $group. |
public bool |
isModified(
)
Returns true if the configuration has been modified since it was initialized with the constructor. |
public void |
removeAllSettings(
)
Removes all groups, settings, values and comments. |
public void |
removeGroup(
$group
)
Removes the group $group from the settings. |
public void |
removeSetting(
$group
, $setting
)
Removes the setting $setting from the group $group. |
public void |
removeSettings(
$group
, $settings
)
Removes the settings $settings from the group $group. |
public void |
setSetting(
$group
, $setting
, $value
, [ $comment
= null] )
Sets the setting $setting in group $group to $value. |
public void |
setSettings(
$group
, $settings
, $values
, [ $comments
= null] )
Sets the settings $setting in group $group to $values. |
Methods
__construct
Constructs the configuration object.
Initializes the configuration object with the groups and the comments. The $settings array contains all the setting groups. The $comments array has the same format. See ezcConfiguration::$settings and ezcConfiguration::$comments for an example of the layout.
Parameters:
Name | Type | Description |
---|---|---|
$settings |
array | |
$comments |
array |
addGroup
Adds a the group $group with the comment $comment the settings.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$comment |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationGroupExistsAlreadyException |
if the group that you are trying to add already exists. |
getAllComments
Returns all the groups and their settings comments as an array.
The returned array looks like:
- array( 'group1' => array( '#' => 'groupcomment',
- 'setting1' => 'comment1',
- 'setting2' => 'comment2' ),
- 'group2' => array( 'setting3' => 'comment3' ) );
getAllSettings
Returns all the groups and their settings and values.
The returned array looks like:
- array( 'group1' => array( 'setting1' => 'value1',
- 'setting2' => 'value2' ),
- 'group2' => array( 'setting3' => 'value3' ) );
getArraySetting
Returns the value of the setting $setting in group $group.
Uses the getSetting() method to fetch the value, this method can throw exceptions. This method also validates whether the value is actually an array value.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownGroupException |
if the group does not exist. |
ezcConfigurationUnknownSettingException |
if the setting does not exist. |
ezcConfigurationSettingWrongTypeException |
if the setting value is not an array. |
getBoolSetting
Returns the value of the setting $setting in group $group.
Uses the getSetting() method to fetch the value, this method can throw exceptions. This method also validates whether the value is actually a boolean value.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownGroupException |
if the group does not exist. |
ezcConfigurationUnknownSettingException |
if the setting does not exist. |
ezcConfigurationSettingWrongTypeException |
if the setting value is not a boolean. |
getComment
Returns the comment belonging to setting $setting located in group $group.
This method returns the comment belonging to the setting that is passed. If there is no comment for this specific setting it returns false.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownSettingException |
if the setting does not exist. |
ezcConfigurationUnknownGroupException |
if the group does not exist. |
getComments
Returns the comments belonging to the specified settings $settings as an array.
This method returns the comments belonging to the settings that are passed. If there is no comment for each specific setting the returning array element will have a value of false.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | The name of the group the settings will be located in. |
$settings |
array |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownSettingException |
if one or more of the settings do not exist. |
ezcConfigurationUnknownGroupException |
if the group does not exist. |
getGroupNames
Returns the names of all the groups as an array.
getNumberSetting
Returns the value of the setting $setting in group $group.
Uses the getSetting() method to fetch the value, this method can throw exceptions. This method also validates whether the value is actually an integer or float value.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownGroupException |
if the group does not exist. |
ezcConfigurationUnknownSettingException |
if the setting does not exist. |
ezcConfigurationSettingWrongTypeException |
if the setting value is not an integer or a float. |
getSetting
Returns the value of setting $setting located in group $group.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownSettingException |
if the setting does not exist. |
ezcConfigurationUnknownGroupException |
if the group does not exist. |
getSettingNames
Returns the names of all settings in the group $group.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownGroupException |
if the group does not exist. |
getSettings
Returns the values of the settings $settings in group $group as an array.
For each of the setting names passed in the $settings array it will return the setting in the returned array with the name of the setting as key.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$settings |
array |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownSettingException |
if one or more of the settings do not exist. |
ezcConfigurationUnknownGroupException |
if the group does not exist. |
getSettingsInGroup
Returns all settings in the group $group.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownGroupException |
if the group does not exist. |
getStringSetting
Returns the value of the setting $setting in group $group.
Uses the getSetting() method to fetch the value, this method can throw exceptions. This method also validates whether the value is actually a string value.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownGroupException |
if the group does not exist. |
ezcConfigurationUnknownSettingException |
if the setting does not exist. |
ezcConfigurationSettingWrongTypeException |
if the setting value is not a string. |
hasGroup
Returns true if the group $group exists.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string |
hasSetting
Returns true if setting $setting exists within the group $group.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string |
hasSettings
Returns true if all the specified settings $settings exists within $group.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$settings |
array(string) |
isModified
Returns true if the configuration has been modified since it was initialized with the constructor.
removeAllSettings
Removes all groups, settings, values and comments.
removeGroup
Removes the group $group from the settings.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownGroupException |
if the group does not exist. |
removeSetting
Removes the setting $setting from the group $group.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownSettingException |
if the setting does not exist. |
ezcConfigurationUnknownGroupException |
if the group does not exist. |
removeSettings
Removes the settings $settings from the group $group.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$settings |
array(string) |
Exceptions:
Type | Description |
---|---|
ezcConfigurationUnknownSettingException |
if one or more of the settings do not exist. |
ezcConfigurationUnknownGroupException |
if the group does not exist. |
setSetting
Sets the setting $setting in group $group to $value.
If the setting does not already exists it will be created.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$setting |
string | |
$value |
mixed | The value of the setting, can be any PHP type except a resource or an object. |
$comment |
string | The comment belonging to the setting |
setSettings
Sets the settings $setting in group $group to $values.
If the settings do not already exists it will be created.
Parameters:
Name | Type | Description |
---|---|---|
$group |
string | |
$settings |
array(string) | |
$values |
array(mixed) | |
$comments |
array(string) | The comment belonging to the setting |