Class LoggerOptionConverter

Description

A convenience class to convert property values to specific types.

  • version: $Revision: 1237446 $
  • since: 0.5

Located in /helpers/LoggerOptionConverter.php (line 29)


	
			
Class Constant Summary
Variable Summary
static mixed $falseValues
static mixed $trueValues
Method Summary
static string findAndSubst (string $key, array $props)
static string getSystemProperty (string $key, string $def)
static string substVars (string $val, [array $props = null])
static boolean toBoolean (string $value, [boolean $default = true])
static void toBooleanEx ( $value)
static float toFileSize (string $value, float $default)
static integer toFileSizeEx (mixed $value)
static integer toInt (string $value, integer $default)
static void toIntegerEx ( $value)
static LoggerLevel toLevel (string $value, LoggerLevel $defaultValue)
static void toLevelEx ( $value)
static void toPositiveIntegerEx ( $value)
static void toStringEx ( $value)
Variables
static mixed $falseValues = array('0', 'false', 'no', 'off', '') (line 46)

String values which are converted to boolean FALSE.

Note that an empty string must convert to false, because parse_ini_file() which is used for parsing configuration converts the value _false_ to an empty string.

  • access: private
static mixed $trueValues = array('1', 'true', 'yes', 'on') (line 37)

String values which are converted to boolean TRUE.

  • access: private
Methods
static findAndSubst (line 350)

Find the value corresponding to $key in $props. Then perform variable substitution on the found value.

  • access: public
static string findAndSubst (string $key, array $props)
  • string $key
  • array $props
static getSystemProperty (line 61)

Read a predefined var.

It returns a value referenced by $key using this search criteria:

  • if $key is a constant then return it. Else
  • if $key is set in $_ENV then return it. Else
  • return $def.

  • return: the string value of the system property, or the default value if there is no property with that key.
  • access: public
static string getSystemProperty (string $key, string $def)
  • string $key: The key to search for.
  • string $def: The default value to return.
static substVars (line 406)

Perform variable substitution in string $val from the values of keys found with the getSystemProperty() method.

The variable substitution delimeters are ${ and }.

For example, if the "MY_CONSTANT" contains "value", then the call

  1.  $s LoggerOptionConverter::substVars("Value of key is ${MY_CONSTANT}.");
will set the variable $s to "Value of key is value.".

If no value could be found for the specified key, then the $props parameter is searched, if the value could not be found there, then substitution defaults to the empty string.

For example, if getSystemProperty() cannot find any value for the key "inexistentKey", then the call

  1.  $s LoggerOptionConverter::substVars("Value of inexistentKey is [${inexistentKey}]");
will set $s to "Value of inexistentKey is []".

A warn is thrown if $val contains a start delimeter "${" which is not balanced by a stop delimeter "}" and an empty string is returned.

  • access: public
static string substVars (string $val, [array $props = null])
  • string $val: The string on which variable substitution is performed.
  • array $props
static toBoolean (line 85)

If $value is true, then true is returned. If $value is false, then true is returned. Otherwise, $default is returned.

Case of value is unimportant.

  • access: public
static boolean toBoolean (string $value, [boolean $default = true])
  • string $value
  • boolean $default
static toBooleanEx (line 105)

Converts $value to boolean, or throws an exception if not possible.

  • access: public
static void toBooleanEx ( $value)
  • $value
static toFileSize (line 246)
  • access: public
static float toFileSize (string $value, float $default)
  • string $value
  • float $default
static toFileSizeEx (line 286)

Converts a value to a valid file size (integer).

Supports 'KB', 'MB' and 'GB' suffixes, where KB = 1024 B etc.

The final value will be rounded to the nearest integer.

Examples:

  • '100' => 100
  • '100.12' => 100
  • '100KB' => 102400
  • '1.5MB' => 1572864

  • return: Parsed file size.
  • access: public
static integer toFileSizeEx (mixed $value)
  • mixed $value: File size (optionally with suffix).
static toInt (line 127)
  • access: public
static integer toInt (string $value, integer $default)
  • string $value
  • integer $default
static toIntegerEx (line 141)

Converts $value to integer, or throws an exception if not possible.

Floats cannot be converted to integer.

  • access: public
static void toIntegerEx ( $value)
  • $value
static toLevel (line 193)

Converts a standard or custom priority level to a Level object.

If $value is of form "level#full_file_classname", where full_file_classname means the class filename with path but without php extension, then the specified class' toLevel() method is called to process the specified level string; if no '#' character is present, then the default LoggerLevel class is used to process the level value.

As a special case, if the $value parameter is equal to the string "NULL", then the value null will be returned.

If any error occurs while converting the value to a level, the $defaultValue parameter, which may be null, is returned.

Case of $value is insignificant for the level level, but is significant for the class name part, if present.

static LoggerLevel toLevel (string $value, LoggerLevel $defaultValue)
static toLevelEx (line 230)

Converts the value to a level. Throws an exception if not possible.

  • access: public
static void toLevelEx ( $value)
  • $value
static toPositiveIntegerEx (line 156)

Converts $value to integer, or throws an exception if not possible.

Floats cannot be converted to integer.

  • access: public
static void toPositiveIntegerEx ( $value)
  • $value
static toStringEx (line 326)

Converts a value to string, or throws an exception if not possible.

Objects can be converted to string if they implement the magic __toString() method.

  • access: public
static void toStringEx ( $value)
  • $value
Class Constants
DELIM_START = '${' (line 31)
DELIM_START_LEN = 2 (line 33)
DELIM_STOP = '}' (line 32)
DELIM_STOP_LEN = 1 (line 34)

Documentation generated on Sat, 18 Feb 2012 22:32:26 +0000 by phpDocumentor 1.4.3