- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml
Classes:
IActiveControl
IBindable
ICache
ICacheDependency
ICallbackEventHandler
IDataRenderer
IModule
IRenderable
IService
IStatePersister
IStyleable
ITextWriter
IUser
Prado
PradoBase
TApplication
TApplicationComponent
TApplicationConfiguration
TApplicationMode
TApplicationStatePersister
TComponent
TComponentReflection
TDraggableConstraint
TDropContainerEventParameter
TEnumerable
TEventParameter
TModule
TPropertyValue
TReflectionClass
TService
TShellApplication

Keyword

# Class TPropertyValue

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
Author: Qiang Xue <qiang.xue@gmail.com>

Method Summary
array | ensureArray ( mixed $value) Converts a value to array type. If the value is a string and it is
boolean | ensureBoolean ( mixed $value) Converts a value to boolean type.
string | ensureEnum ( mixed $value, mixed $enums) Converts a value to enum type.
float | ensureFloat ( mixed $value) Converts a value to float type.
integer | ensureInteger ( mixed $value) Converts a value to integer type.
object | ensureObject ( mixed $value) Converts a value to object type.
string | ensureString ( mixed $value) Converts a value to string type.

Method Details

## ensureArray

public 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

Input
mixed | $value | the value to be converted.
Output
Exception

## ensureBoolean

public 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.

Input
mixed | $value | the value to be converted.
Output
Exception

## ensureEnum

public string ensureEnum | (mixed $value , mixed $enums )

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.

Input
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.
Output
string | the valid enumeration value
Exception
throws | TInvalidDataValueException if the original value is not in the string array.

## ensureFloat

public float ensureFloat | (mixed $value )

Converts a value to float type.

Input
mixed | $value | the value to be converted.
Output
Exception

## ensureInteger

public integer ensureInteger | (mixed $value )

Converts a value to integer type.

Input
mixed | $value | the value to be converted.
Output
Exception

## ensureObject

public object ensureObject | (mixed $value )

Converts a value to object type.

Input
mixed | $value | the value to be converted.
Output
Exception

## ensureString

public 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.

Input
mixed | $value | the value to be converted.
Output
Exception