## Class TPropertyValue

Description

TPropertyValue class

TPropertyValue is a utility class that provides static methods to convert component property values to specific types.

TPropertyValue is commonly used in component setter methods to ensure the new property value is of specific type. For example, a boolean-typed property setter method would be as follows,

     function setPropertyName($value) {
         $value=TPropertyValue::ensureBoolean($value);
         // $value is now of boolean type
     }

Properties can be of the following types with specific type conversion rules:

- string: a boolean value will be converted to 'true' or 'false'.
- boolean: string 'true' (case-insensitive) will be converted to true, string 'false' (case-insensitive) will be converted to false.
- integer
- float
- array: string starting with '(' and ending with ')' will be considered as as an array expression and will be evaluated. Otherwise, an array with the value to be ensured is returned.
- object
- enum: enumerable type, represented by an array of strings.

- since: 3.0
- version: $Id: TComponent.php 2541 2008-10-21 15:05:13Z qiang.xue $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /TComponent.php (line 515)

Method Summary
array ensureArray (mixed $value)
boolean ensureBoolean (mixed $value)
string ensureEnum (mixed $value, mixed $enums)
float ensureFloat (mixed $value)
integer ensureInteger (mixed $value)
object ensureObject (mixed $value)
string ensureString (mixed $value)
Methods
ensureArray (line 577)

Converts a value to array type. If the value is a string and it is

in the form (a,b,c) then an array consisting of each of the elements will be returned. If the value is a string and it is not in this form then an array consisting of just the string will be returned. If the value is not a string then

- static:
- access: public

array ensureArray (mixed $value)

- mixed $value: the value to be converted.

ensureBoolean (line 525)

Converts a value to boolean type.

Note, string 'true' (case-insensitive) will be converted to true, string 'false' (case-insensitive) will be converted to false. If a string represents a non-zero number, it will be treated as true.

- static:
- access: public

boolean ensureBoolean (mixed $value)

- mixed $value: the value to be converted.

ensureEnum (line 621)

Converts a value to enum type.

This method checks if the value is of the specified enumerable type. A value is a valid enumerable value if it is equal to the name of a constant in the specified enumerable type (class). For more details about enumerable, see TEnumerable.

For backward compatibility, this method also supports sanity check of a string value to see if it is among the given list of strings.

- return: the valid enumeration value
- static:
- access: public
- throws: TInvalidDataValueException if the original value is not in the string array.

string ensureEnum (mixed $value, mixed $enums)

- mixed $value: the value to be converted.
- mixed $enums: class name of the enumerable type, or array of valid enumeration values. If this is not an array, the method considers its parameters are of variable length, and the second till the last parameters are enumeration values.

ensureFloat (line 563)

Converts a value to float type.

- static:
- access: public

float ensureFloat (mixed $value)

- mixed $value: the value to be converted.

ensureInteger (line 553)

Converts a value to integer type.

- static:
- access: public

integer ensureInteger (mixed $value)

- mixed $value: the value to be converted.

ensureObject (line 600)

Converts a value to object type.

- static:
- access: public

object ensureObject (mixed $value)

- mixed $value: the value to be converted.

ensureString (line 540)

Converts a value to string type.

Note, a boolean value will be converted to 'true' if it is true and 'false' if it is false.

- static:
- access: public

string ensureString (mixed $value)

- mixed $value: the value to be converted.

Documentation generated on Mon, 22 Feb 2010 12:17:09 +0000 by phpDocumentor 1.3.0RC4