Erebot  latest
A modular IRC bot for PHP 5.3+
Erebot\Interfaces\Config\Proxy Interface Reference

Interface for a generic cascading configuration. More...

+ Inheritance diagram for Erebot\Interfaces\Config\Proxy:

Public Member Functions

 getMainCfg ()
 
 getModule ($moduleName)
 
 getModules ($recursive)
 
 getTranslator ($component)
 
 parseBool ($module, $param, $default=null)
 
 parseInt ($module, $param, $default=null)
 
 parseReal ($module, $param, $default=null)
 
 parseString ($module, $param, $default=null)
 

Detailed Description

Interface for a generic cascading configuration.

This interface provides methods which are common to different configuration interfaces.

Definition at line 30 of file Proxy.php.

Member Function Documentation

Erebot\Interfaces\Config\Proxy::getMainCfg ( )

Returns the root configuration associated with this hierarchy of configurations.

Return values
Erebot::Interfaces::Config::MainThe main configuration of the bot.
Erebot\Interfaces\Config\Proxy::getModule (   $moduleName)

Returns the instance of the module configuration with the given name.

Parameters
string$moduleNameName of the module whose configuration we're insterested in.
Return values
Erebot::Interfaces::Config::ModuleInstance of the module's configuration.
Exceptions
ErebotNotFoundException
Erebot\Interfaces\Config\Proxy::getModules (   $recursive)

Returns a list with the names of all currently active modules.

Parameters
bool$recursiveIf set to TRUE, the list is retrieved recursively by merging the lists obtained at this level and all levels above it. If set to FALSE, only the modules activated at this particular level are returned.
Return values
list(string)A list with the names of currently active modules.
Erebot\Interfaces\Config\Proxy::getTranslator (   $component)

Returns the appropriate i18n object to use for translations at this configuration level.

Parameters
string$componentName of the component we're interested in. This should be set to the name of a module or "Erebot" for the core translator.
Return values
Erebot::IntlInterfaceA translator object.
Exceptions
Erebot::NotFoundExceptionNo appropriate translator exists for this configuration level.

Implemented in Erebot\Config\Main.

Erebot\Interfaces\Config\Proxy::parseBool (   $module,
  $param,
  $default = null 
)

Returns the boolean value for a setting in some module.

Parameters
string$moduleThe name of the module from which to retrieved the setting.
string$paramThe name of the parameter we are interested in.
bool$default(optional) A default value in case no value has been set at the configuration level.
Return values
boolThe boolean value for that particular module and parameter.
Exceptions
Erebot::NotFoundExceptionThe given $module or $param name could not be found.
Erebot::InvalidValueExceptionA value could be retrieved, but its type is not the one we expected (it was NOT a boolean). Either the configuration file contains an invalid value, or no value has been defined in the configuration file and the $default value is invalid.
Note
This method tries to retrieve the value recursively by traversing the configuration hierarchy.
Erebot\Interfaces\Config\Proxy::parseInt (   $module,
  $param,
  $default = null 
)

Returns the integer value for a setting in some module.

Parameters
string$moduleThe name of the module from which to retrieved the setting.
string$paramThe name of the parameter we are interested in.
int$default(optional) A default value in case no value has been set at the configuration level.
Return values
intThe interger value for that particular module and parameter.
Exceptions
Erebot::NotFoundExceptionThe given $module or $param name could not be found.
Erebot::InvalidValueExceptionA value could be retrieved, but its type is not the one we expected (it was NOT an integer). Either the configuration file contains an invalid value, or no value has been defined in the configuration file and the $default value is invalid.
Note
The returned value is always signed. There is currently no way to restrict the range of allowed values using this function. If you need to apply restrictions, do it in the calling function:
$port = $config->parseInt('server', 'incomingPort');
if ($port <= 0 || $port > 65535)
throw new \\Erebot\\InvalidValueException(
"Incoming port value is out of range (1-65535)");
// Else, use the $port value to create a listening socket, etc.
This method tries to retrieve the value recursively by traversing the configuration hierarchy.
Erebot\Interfaces\Config\Proxy::parseReal (   $module,
  $param,
  $default = null 
)

Returns the real number for a setting in some module.

Parameters
string$moduleThe name of the module from which to retrieved the setting.
string$paramThe name of the parameter we are interested in.
float$default(optional) A default value in case no value has been set at the configuration level.
Return values
floatThe real number for that particular module and parameter.
Exceptions
Erebot::NotFoundExceptionThe given $module or $param name could not be found.
Erebot::InvalidValueExceptionA value could be retrieved, but its type is not the one we expected (it was NOT a real). Either the configuration file contains an invalid value, or no value has been defined in the configuration file and the $default value is invalid.
Note
The returned value is not restricted in nay way. If you need to apply restrictions, do it in the calling function:
$price = $config->parseReal('prices', '$item);
if ($price <= 0.1)
throw \\Erebot\\InvalidValueException(
"Invalid price: we're losing money here!");
This method tries to retrieve the value recursively by traversing the configuration hierarchy.
Erebot\Interfaces\Config\Proxy::parseString (   $module,
  $param,
  $default = null 
)

Returns the string value for a setting in some module.

Parameters
string$moduleThe name of the module from which to retrieved the setting.
string$paramThe name of the parameter we are interested in.
string$default(optional) A default value in case no value has been set at the configuration level.
Return values
stringThe string value for that particular module and parameter.
Exceptions
Erebot::NotFoundExceptionThe given $module or $param name could not be found.
Erebot::InvalidValueExceptionA value could be retrieved, but its type is not the one we expected (it was NOT a string). Either the configuration file contains an invalid value, or no value has been defined in the configuration file and the $default value is invalid.
Note
This method tries to retrieve the value recursively by traversing the configuration hierarchy.

The documentation for this interface was generated from the following file: