Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcConfigurationManager

Configuration::ezcConfigurationManager

Class ezcConfigurationManager

ezcConfigurationManager provides easy access to application settings.

Using this class removes the need to work with specific readers and writers and also handles caching to speed up the process. This can be useful for smaller applications which don't have too many settings and does not have high memory or speed requirements.

Many of the methods of this class that fetch settings accept one to three parameters with the following names: $name - the configuration's name. For the ini file reader, this is the name of the configuration file without the path or the extension (.ini); $group - the name of the group in which the setting is located; and $setting - the name of the setting itself.

Before the manager can be used it must be configured so it knows where to fetch the settings, this is usually at the start of the program.

  1.  $man->init( 'ezcConfigurationIniReader', 'settings', $options );

After it is configured the rest of the code can simply access the global instance and fetch the settings using getSetting().

  1.  $color = ezcConfigurationManager::getInstance()->getSetting( 'site', 'Colors', 'Background' );

Source for this file: /Configuration/src/configuration_manager.php

Version:   //autogen//

Method Summary

public static ezcConfigurationManager getInstance( )
Returns the instance of the class ezcConfigurationManager.
public bool exists( $name )
Returns true if the configuration named $name exists.
public array getArraySetting( $name , $group , $setting )
Returns the value of the setting $setting in group $group in the configuration named $name.
public bool getBoolSetting( $name , $group , $setting )
Returns the value of the setting $setting in group $group in the configuration named $name.
public int getNumberSetting( $name , $group , $setting )
Returns the value of the setting $setting in group $group in the configuration named $name.
public mixed getSetting( $name , $group , $setting )
Returns the value of the setting $setting in group $group in the configuration named $name.
public array getSettings( $name , $group , $settings )
Returns the values of the settings $settings in group $group in the configuration named $name.
public array getSettingsAsList( $name , $group , $settings )
Returns the values of the settings $settings in group $group as an array.
public array getSettingsInGroup( $name , $group )
Returns all settings in group $group in the configuration named $name.
public string getStringSetting( $name , $group , $setting )
Returns the value of the setting $setting in group $group in the configuration named $name.
public bool hasConfigFile( $name )
Returns if the requested configuration file exists.
public bool hasGroup( $name , $group )
Returns whether the setting $group group exists in the configuration named $name.
public bool hasSetting( $name , $group , $setting )
Returns whether the setting $setting exists in group $group in the configuration named $name.
public void init( $readerClass , $location , [ $options = array()] )
Initializes the manager.
public void reset( )
Resets the manager to the uninitialized state.

Methods

getInstance

static ezcConfigurationManager getInstance( )

Returns the instance of the class ezcConfigurationManager.

exists

bool exists( string $name )

Returns true if the configuration named $name exists.

Parameters:
Name Type Description
$name string
Exceptions:
Type Description
ezcConfigurationManagerNotInitializedException if the manager has not been initialized with the init() method.

getArraySetting

array getArraySetting( string $name , string $group , string $setting )

Returns the value of the setting $setting in group $group in the configuration named $name.

Uses the fetchSetting() 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
$name string
$group string
$setting string
Exceptions:
Type Description
ezcConfigurationUnknownConfigException if the configuration does not exist.
ezcConfigurationUnknownGroupException if the group does not exist.
ezcConfigurationUnknownSettingException if the setting does not exist.
ezcConfigurationSettingWrongTypeException if the setting value is not an array.

getBoolSetting

bool getBoolSetting( string $name , string $group , string $setting )

Returns the value of the setting $setting in group $group in the configuration named $name.

Uses the fetchSetting() 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
$name string
$group string
$setting string
Exceptions:
Type Description
ezcConfigurationUnknownConfigException if the configuration does not exist.
ezcConfigurationUnknownGroupException if the group does not exist.
ezcConfigurationUnknownSettingException if the setting does not exist.
ezcConfigurationSettingWrongTypeException if the setting value is not a boolean.

getNumberSetting

int getNumberSetting( string $name , string $group , string $setting )

Returns the value of the setting $setting in group $group in the configuration named $name.

Uses the fetchSetting() method to fetch the value, this method can throw exceptions. This method also validates whether the value is actually an integer value.

Parameters:
Name Type Description
$name string
$group string
$setting string
Exceptions:
Type Description
ezcConfigurationUnknownConfigException if the configuration does not exist.
ezcConfigurationUnknownGroupException if the group does not exist.
ezcConfigurationUnknownSettingException if the setting does not exist.
ezcConfigurationSettingWrongTypeException if the setting value is not a number.

getSetting

mixed getSetting( string $name , string $group , string $setting )

Returns the value of the setting $setting in group $group in the configuration named $name.

Uses the fetchSetting() method to fetch the value, this method can throw exceptions.

Parameters:
Name Type Description
$name string
$group string
$setting string
Exceptions:
Type Description
ezcConfigurationUnknownConfigException if the configuration does not exist.
ezcConfigurationUnknownGroupException if the group does not exist.
ezcConfigurationUnknownSettingException if the setting does not exist.

getSettings

array getSettings( string $name , string $group , $settings )

Returns the values of the settings $settings in group $group in the configuration named $name.

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
$name string
$group string
$settings array
Exceptions:
Type Description
ezcConfigurationUnknownConfigException if the configuration does not exist.
ezcConfigurationUnknownGroupException if the group does not exist.
ezcConfigurationUnknownSettingException if one or more of the settings do not exist.

getSettingsAsList

array getSettingsAsList( string $name , string $group , $settings )

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 only return the values of the settings in the returned array, and not include the name of the setting as the array's key.

Parameters:
Name Type Description
$name string
$group string
$settings array
Exceptions:
Type Description
ezcConfigurationUnknownConfigException if the configuration does not exist.
ezcConfigurationUnknownGroupException if the group does not exist.
ezcConfigurationUnknownSettingException if one or more of the settings do not exist.

getSettingsInGroup

array getSettingsInGroup( string $name , string $group )

Returns all settings in group $group in the configuration named $name.

Parameters:
Name Type Description
$name string
$group string
Exceptions:
Type Description
ezcConfigurationUnknownGroupException if the group does not exist.

getStringSetting

string getStringSetting( string $name , string $group , string $setting )

Returns the value of the setting $setting in group $group in the configuration named $name.

Uses the fetchSetting() 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
$name string
$group string
$setting string
Exceptions:
Type Description
ezcConfigurationUnknownConfigException if the configuration does not exist.
ezcConfigurationUnknownGroupException if the group does not exist.
ezcConfigurationUnknownSettingException if the setting does not exist.
ezcConfigurationSettingWrongTypeException if the setting value is not a string.

hasConfigFile

bool hasConfigFile( string $name )

Returns if the requested configuration file exists.

Returns a boolean value indicating whether the configuration file exists or not.

Parameters:
Name Type Description
$name string
Exceptions:
Type Description
ezcConfigurationManagerNotInitializedException if the manager has not been initialized with the init() method.

hasGroup

bool hasGroup( string $name , string $group )

Returns whether the setting $group group exists in the configuration named $name.

Parameters:
Name Type Description
$name string
$group string

hasSetting

bool hasSetting( string $name , string $group , string $setting )

Returns whether the setting $setting exists in group $group in the configuration named $name.

Parameters:
Name Type Description
$name string
$group string
$setting string
Exceptions:
Type Description
ezcConfigurationManagerNotInitializedException if the manager has not been initialized with the init() method.
ezcConfigurationUnknownConfigException if the configuration does not exist.

init

void init( string $readerClass , string $location , [ $options = array()] )

Initializes the manager.

Initializes the manager with the values which will be used by the configuration reader. It sets the default location and reader options and which reader to use by specifying the class name.

Parameters:
Name Type Description
$readerClass string The name of the class to use as a configuration reader. This class must implement the ezcConfigurationReader interface.
$location string The main placement for the configuration. It is up to the specific reader to interpret this value. This can for instance be used to determine the directory location for an INI file.
$options array Options for the configuration reader, this is passed on the reader specified in $readerClass when it is created. Check the documentation for the specific reader to see which options it supports.
Exceptions:
Type Description
ezcConfigurationInvalidReaderClassException if the $readerClass does not exist or does not implement the ezcConfigurationReader interface.

reset

void reset( )

Resets the manager to the uninitialized state.

Documentation generated by phpDocumentor 1.4.3