Class CPropertyValue
CPropertyValue is a helper class that provides static methods to convert component property values to specific types.
CPropertyValue is commonly used in component setter methods to ensure the new property value is of the specific type. For example, a boolean-typed property setter method would be as follows,
public function setPropertyName($value) { $value=CPropertyValue::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.
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/utils/CPropertyValue.php
public static
boolean
|
#
ensureBoolean( mixed $value )
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. |
public static
string
|
#
ensureString( mixed $value )
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. |
public static
integer
|
|
public static
float
|
|
public static
array
|
#
ensureArray( mixed $value )
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 |
public static
object
|
|
public static
string
|