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

A configuration proxy which cascades settings. More...

+ Inheritance diagram for Erebot\Config\Proxy:

Public Member Functions

 __clone ()
 
 __destruct ()
 
 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)
 

Static Public Member Functions

static parseBoolHelper ($value)
 
static parseIntHelper ($value)
 
static parseRealHelper ($value)
 

Protected Member Functions

 __construct (\Erebot\Interfaces\Config\Proxy $proxified,\SimpleXMLElement $xml)
 
 parseSomething ($module, $param, $default,\Erebot\CallableInterface $parser, $origin,\Erebot\CallableInterface $checker)
 

Protected Attributes

 $locale
 The current locale.
 
 $modules
 Array of modules loaded at this particular configuration level.
 
 $proxified
 Reference to a proxified object.
 

Detailed Description

A configuration proxy which cascades settings.

This class is used to build a hierarchy of configurations. Each level in this hierarchy may override settings applied at upper levels. If no override has been made on some setting, that setting retains the value it had on the preceding level. This allows settings to be cascaded in the hierarchy of configuration levels.

The root of the hierarchy acts as a proxy for itself and always implements Erebot::Interfaces::Config::Main.

Definition at line 37 of file Proxy.php.

Constructor & Destructor Documentation

Erebot\Config\Proxy::__construct ( \Erebot\Interfaces\Config\Proxy  $proxified,
\SimpleXMLElement  $xml 
)
protected

Creates a new Erebot::Proxy::Config object.

Parameters
Erebot::Interfaces::Config::Proxy$proxifiedA configuration object which should be proxied through this instance. This allows settings to be cascaded.
SimpleXMLElement$xmlAn XML node which should be used as the basis for configuration.

Definition at line 58 of file Proxy.php.

References Erebot\Config\Proxy\$proxified.

Erebot\Config\Proxy::__destruct ( )

Destructor. Takes care of breaking possible circular references.

Definition at line 86 of file Proxy.php.

Member Function Documentation

Erebot\Config\Proxy::__clone ( )

Copy constructor.

Definition at line 97 of file Proxy.php.

Erebot\Config\Proxy::getMainCfg ( )

Returns the root configuration associated with this hierarchy of configurations.

Return values
Erebot::Interfaces::Config::MainThe main configuration of the bot.

Definition at line 132 of file Proxy.php.

Erebot\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

Definition at line 170 of file Proxy.php.

Erebot\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.

Definition at line 141 of file Proxy.php.

Erebot\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.

Definition at line 103 of file Proxy.php.

References Erebot\IntlInterface\LC_MESSAGES, Erebot\IntlInterface\LC_MONETARY, Erebot\IntlInterface\LC_NUMERIC, and Erebot\IntlInterface\LC_TIME.

Erebot\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.

Definition at line 352 of file Proxy.php.

References Erebot\Config\Proxy\parseSomething(), and Erebot\CallableWrapper\wrap().

Referenced by Erebot\Config\Main\load().

static Erebot\Config\Proxy::parseBoolHelper (   $value)
static

Parses a text and tries to extract a boolean value.

Parameters
string$valueThe text from which a boolean should be extracted.
Return values
boolIf a boolean could be extracted from the $value provided, it is returned as the corresponding PHP boolean value (either true or false).
nullNo boolean could be extracted.
Note
Currently, the following texts are recognized as true: "true", "1", "on" & "yes", while the values "false", "0", "off" & "no" are recognized as false. The comparison is case-insensitive (ie. "true" == "TrUe").

Definition at line 203 of file Proxy.php.

Erebot\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.

Definition at line 378 of file Proxy.php.

References Erebot\Config\Proxy\parseSomething(), and Erebot\CallableWrapper\wrap().

static Erebot\Config\Proxy::parseIntHelper (   $value)
static

Parses a text and tries to extract an integer value.

Parameters
string$valueThe text from which an integer should be extracted.
Return values
intIf an integer could be extracted from the $value provided, it is returned as the corresponding PHP (signed) integer value.
nullIf no integer could be extracted.

Definition at line 228 of file Proxy.php.

Erebot\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.

Definition at line 391 of file Proxy.php.

References Erebot\Config\Proxy\parseSomething(), and Erebot\CallableWrapper\wrap().

static Erebot\Config\Proxy::parseRealHelper (   $value)
static

Parses a text and tries to extract a real.

Parameters
string$valueThe text from which a real should be extracted.
Return values
floatIf a real could be extracted from the $value provided, it is returned as the corresponding PHP float value.
nullIf no real could be extracted.

Definition at line 262 of file Proxy.php.

Erebot\Config\Proxy::parseSomething (   $module,
  $param,
  $default,
\Erebot\CallableInterface  $parser,
  $origin,
\Erebot\CallableInterface  $checker 
)
protected

Returns the typed value for a module's parameter.

Parameters
string$moduleThe name of the module.
string$paramThe name of the parameter to fetch from the module's settings.
mixed$defaultDefault value if no value has been defined in the module's settings, or null if there is no default value.
Erebot::CallableInterface$parserObject that will be used to parse the parameter. It will receive the value of that parameter as a string and should convert it to the proper type.
string$originName of the method the request to parse the parameter originated from.
Erebot::CallableInterface$checkerObject that will be passed the parsed value and should return true if it respects the type constraints defined by this checker, or false if it does not.
Return values
mixedValue as parsed from the module's settings, or the default value if no value existed in the settings and it passed the type check.
Exceptions
Erebot::InvalidValueExceptionThe value parsed or the default value did not pass the type check.
Erebot::NotFoundException

Definition at line 313 of file Proxy.php.

Referenced by Erebot\Config\Proxy\parseBool(), Erebot\Config\Proxy\parseInt(), Erebot\Config\Proxy\parseReal(), and Erebot\Config\Proxy\parseString().

Erebot\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.

Definition at line 365 of file Proxy.php.

References Erebot\Config\Proxy\parseSomething(), and Erebot\CallableWrapper\wrap().


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