PHP 클래스 Prado\TPropertyValue

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.
부터: 3.0
저자: Qiang Xue ([email protected])
파일 보기 프로젝트 열기: pradosoft/prado 1 사용 예제들

공개 메소드들

메소드 설명
ensureArray ( $value ) : array 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
ensureBoolean ( $value ) : boolean Converts a value to boolean type.
ensureEnum ( $value, $enums ) : string Converts a value to enum type.
ensureFloat ( $value ) : float Converts a value to float type.
ensureInteger ( $value ) : integer Converts a value to integer type.
ensureNullIfEmpty ( $value ) : mixed Converts the value to 'null' if the given value is empty
ensureObject ( $value ) : object Converts a value to object type.
ensureString ( $value ) : string Converts a value to string type.

메소드 상세

ensureArray() 공개 정적인 메소드

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 ensureArray ( $value ) : array
리턴 array

ensureBoolean() 공개 정적인 메소드

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 ensureBoolean ( $value ) : boolean
리턴 boolean

ensureEnum() 공개 정적인 메소드

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 {@link 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.
public static ensureEnum ( $value, $enums ) : string
리턴 string the valid enumeration value

ensureFloat() 공개 정적인 메소드

Converts a value to float type.
public static ensureFloat ( $value ) : float
리턴 float

ensureInteger() 공개 정적인 메소드

Converts a value to integer type.
public static ensureInteger ( $value ) : integer
리턴 integer

ensureNullIfEmpty() 공개 정적인 메소드

Converts the value to 'null' if the given value is empty
public static ensureNullIfEmpty ( $value ) : mixed
리턴 mixed input or NULL if input is empty

ensureObject() 공개 정적인 메소드

Converts a value to object type.
public static ensureObject ( $value ) : object
리턴 object

ensureString() 공개 정적인 메소드

Note, a boolean value will be converted to 'true' if it is true and 'false' if it is false.
public static ensureString ( $value ) : string
리턴 string